package com.phison.fenestrapro.dashboard;

import org.vaadin.hezamu.googlemapwidget.GoogleMap;
import org.vaadin.hezamu.googlemapwidget.GoogleMap.MarkerMovedListener;
import org.vaadin.hezamu.googlemapwidget.GoogleMap.MapControl;
import org.vaadin.hezamu.googlemapwidget.overlay.BasicMarker;
import org.vaadin.hezamu.googlemapwidget.overlay.Marker;

import com.invient.vaadin.charts.InvientCharts;

import org.netomi.vaadin.screenshot.Screenshot;
import org.netomi.vaadin.screenshot.Screenshot.ScreenshotListener;

import com.phison.fenestrapro.dashboard.data.Project;
import com.phison.fenestrapro.dashboard.data.ProjectBean;
import com.phison.fenestrapro.dashboard.ui.LoginWindow;
import com.phison.fenestrapro.dashboard.util.DatabaseHelper;
import com.phison.fenestrapro.dashboard.util.FormBuilder;
import com.phison.fenestrapro.dashboard.util.Functions;
import com.phison.fenestrapro.dashboard.util.GlobalConstants;
import com.phison.fenestrapro.dashboard.util.GridFormBuilder;
import com.phison.fenestrapro.dashboard.util.PdfHelper;
import com.phison.fenestrapro.dashboard.util.SendMail;

import java.awt.geom.Point2D;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.vaadin.Application;
import com.vaadin.data.util.BeanItem;
import com.vaadin.data.util.MethodProperty;
import com.vaadin.service.ApplicationContext.TransactionListener;
import com.vaadin.terminal.ExternalResource;
import com.vaadin.terminal.Sizeable;
import com.vaadin.terminal.StreamResource;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.terminal.gwt.server.HttpServletRequestListener;
import com.vaadin.terminal.gwt.server.WebApplicationContext;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.Accordion;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import com.vaadin.ui.TabSheet.Tab;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Window.ResizeEvent;
import com.vaadin.ui.Window.ResizeListener;
import com.vaadin.ui.themes.Runo;

/**
 * This is the main Application class
 * 
 * @author Niall O'Hara
 *
 */
@SuppressWarnings("serial")
public class FenestraProApplication extends Application implements
		HttpServletRequestListener, GlobalConstants, TransactionListener, ScreenshotListener  {
	
	private static final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	
	private Screenshot screenshot;
	
	private Embedded image;
	
	private String selectedTabName;
	
	private TabSheet tabSheetLeft;
	private TabSheet tabSheetRight;
	
	// Session Time (seconds)
	private static final int SESSION_TIMEOUT_AFTER = 900;
	
	// build number from last commit to svn
	private int buildNumber = 224;
	
	// for development in TCD (allows access to google maps api)
	private boolean enableProxy = false;
	
	// Turn off login for debug purposes
	private boolean enableLogin = true;
	
	private int debugUserID = 1;
	private int debugCompanyID = 17;
		
	// prototype restrictions
	private int maxProjects = 6;
	
	// the number of projects the user has
	private int liveProjects = 0;
	
	// logged in user details
	private Integer currentUserID = null; // needs to be null as this is used to prevent multiple logins
	private int currentCompanyID;
	private String currentUserFirstName = null;
	private String currentUserSecondName = null;
	private String currentCompanyName = null;
	
	/**
	 * @return the current build number
	 */
	public int getBuildNumber() {
		return buildNumber;
	}
	
	/**
	 * @return the logged in users first name
	 */
	public String getCurrentUserFirstName() {
		return currentUserFirstName;
	}

	/**
	 * @return the logged in users second name
	 */
	public String getCurrentUserSecondName() {
		return currentUserSecondName;
	}
	
	/**
	 * @return the company name associated with the logged in user
	 */
	public String getCurrentCompany() {
		return currentCompanyName;
	}
	
	private Panel left = new Panel();
	private TabSheet right = new TabSheet();
	//private TabSheet styles = new TabSheet();
	//private TabSheet samples = new TabSheet();
	
	private DatabaseHelper database = new DatabaseHelper();
	
	final Project[] projectArray = new Project[maxProjects];
	
	final Tab[] projectTabArray = new Tab[maxProjects];
	
	private int userProjectIDs[];
	
	@SuppressWarnings("unchecked")
	final BeanItem<Project>[] buildingBeanItemArray = new BeanItem[maxProjects];
	
	final FormBuilder[] formBuilderArray = new FormBuilder[maxProjects];
	
	final GridFormBuilder[] gridFormBuilderArray = new GridFormBuilder[maxProjects];
	
	// we have to pre-generate these in oder to allow for dynamic selection via the no. of storeys
	final GridLayout[] contentLayoutDaylightFacadeOneArray = new GridLayout[maxProjects];
	final GridLayout[] contentLayoutDaylightFacadeTwoArray = new GridLayout[maxProjects];
	final GridLayout[] contentLayoutDaylightFacadeThreeArray = new GridLayout[maxProjects];
	final GridLayout[] contentLayoutDaylightFacadeFourArray = new GridLayout[maxProjects];
	
	static final Object[] PROJECT_DETAILS_FORM = new Object[] { "projName",
			"projNumber", "projDescription", "buildingType", "facadeType", "locationSetting", "latitude", "longitude" };

	static final Object[] BUILDING_MANAGER_FORM = new Object[] { "length",
			"width", "storeys", "floorToFloor", "overallBuildingHeight",
			"floorToCeiling" };

	static final Object[] OVERALL_PERFORMANCE_REQUIREMENT_FORM = new Object[] { "facadePerformance", "facadeExcellence", "maxAverageUvalueFacade", "facadePerformanceValue" };

	static final Object[] ELEMENTAL_VALUES_FORM = new Object[] { "uValueRoof", "uValueRoofValue", "uValueGroundFloor", "uValueGroundFloorValue", "uValueGlazing", "uValueGlazingValue", "uValueWalls", "uValueWallsValue" };

	static final Object[] OVERALL_PERCENTAGE_GLAZING_FROM = new Object[] { "maxPercentageGlazing", "percentageGlazing", "percentageGlazingValue", "glazingWallRatio" };

	public static final Object[] BUILDING_ORIENTATION_FORM = new Object[] { "orientation" };
	
	public static final Object[] BUILDING_LATLONG_FORM = new Object[] { "longitude", "latitude" };

	public static final Object[] GLAZING_DISTRIBUTION_FORM = new Object[] {
		"facadeOneGlazedPercentage", "facadeOneGlazedAreaLock",
		"facadeTwoGlazedPercentage", "facadeTwoGlazedAreaLock",
		"facadeThreeGlazedPercentage", "facadeThreeGlazedAreaLock",
		"facadeFourGlazedPercentage", "facadeFourGlazedAreaLock" };
	
	public static final Object[] FACADE_ONE_MANAGER_FORM = new Object[] {
		"facadeOneGlazedPercentage", "facadeOneGlazedAreaLock", "facadeOneGlazingType", 
		"facadeOneSolarTransmittanceRO", 
		"facadeOneGlazingSpec", "facadeOnePercentageFrame", "facadeOneWindowShadingType",
		"facadeOneShadingFactorRO", "facadeOneWindowConfig", "facadeOneLouvreColour", 
		"facadeOneWindowShadingDepth", "facadeOneSlatAngle", "facadeOneShadingAngle"
	};
	
	public static final Object[] FACADE_TWO_MANAGER_FORM = new Object[] {
		"facadeTwoGlazedPercentage", "facadeTwoGlazedAreaLock", "facadeTwoGlazingType", 
		"facadeTwoSolarTransmittanceRO", 
		"facadeTwoGlazingSpec", "facadeTwoPercentageFrame", "facadeTwoWindowShadingType",
		"facadeTwoShadingFactorRO",
		"facadeTwoWindowConfig", "facadeTwoWindowShadingDepth", "facadeTwoShadingAngle",
		"facadeTwoLouvreColour", "facadeTwoSlatAngle"
	};
	
	public static final Object[] FACADE_THREE_MANAGER_FORM = new Object[] {
		"facadeThreeGlazedPercentage", "facadeThreeGlazedAreaLock", "facadeThreeGlazingType", 
		"facadeThreeSolarTransmittanceRO", 
		"facadeThreeGlazingSpec", "facadeThreePercentageFrame", "facadeThreeWindowShadingType",
		"facadeThreeShadingFactorRO",
		"facadeThreeWindowConfig", "facadeThreeWindowShadingDepth", "facadeThreeShadingAngle",
		"facadeThreeLouvreColour", "facadeThreeSlatAngle"
	};
	
	public static final Object[] FACADE_FOUR_MANAGER_FORM = new Object[] {
		"facadeFourGlazedPercentage", "facadeFourGlazedAreaLock", "facadeFourGlazingType", 
		"facadeFourSolarTransmittanceRO", 
		"facadeFourGlazingSpec", "facadeFourPercentageFrame", "facadeFourWindowShadingType",
		"facadeFourShadingFactorRO",
		"facadeFourWindowConfig", "facadeFourWindowShadingDepth", "facadeFourShadingAngle",
		"facadeFourLouvreColour", "facadeFourSlatAngle"
	};

	public static final Object[] FACADE_ONE_DAYLIGHT_FORM = new Object[] {
		"facadeOneDiffuseTransmittanceValue", "facadeOneSurroundingFeaturesAverageHeight",
		"facadeOneSurroundingFeaturesAverageDistance"
	};
	
	public static final Object[] FACADE_TWO_DAYLIGHT_FORM = new Object[] {
		"facadeTwoDiffuseTransmittanceValue", "facadeTwoSurroundingFeaturesAverageHeight",
		"facadeTwoSurroundingFeaturesAverageDistance"
		
	};
	
	public static final Object[] FACADE_THREE_DAYLIGHT_FORM = new Object[] {
		"facadeThreeDiffuseTransmittanceValue", "facadeThreeSurroundingFeaturesAverageHeight",
		"facadeThreeSurroundingFeaturesAverageDistance"
	};
	
	public static final Object[] FACADE_FOUR_DAYLIGHT_FORM = new Object[] {
		"facadeFourDiffuseTransmittanceValue", "facadeFourSurroundingFeaturesAverageHeight",
		"facadeFourSurroundingFeaturesAverageDistance"
	};
	
	public static final Object[] SOLAR_SHADING_FORM = new Object[] {
			"facadeOneAverageSolarLoad", "facadeOnePercentageFrame",
			"facadeOneSolarTransmittance", "facadeOneShadingFactor",
			"facadeTwoAverageSolarLoad", "facadeTwoPercentageFrame",
			"facadeTwoSolarTransmittance", "facadeTwoShadingFactor",
			"facadeThreeAverageSolarLoad", "facadeThreePercentageFrame",
			"facadeThreeSolarTransmittance", "facadeThreeShadingFactor",
			"facadeFourAverageSolarLoad", "facadeFourPercentageFrame",
			"facadeFourSolarTransmittance", "facadeFourShadingFactor" };

	public static final Object[] OUTPUT_INFO_BUILDING_TOTALS_FORM = new Object[] {
			"facadeOneArea", "facadeTwoArea", "facadeThreeArea",
			"facadeFourArea", "totalFacadeArea", "roofArea", "groundFloorArea",
			"areaOfInternalSurfaces", "roofAndGroundFloorArea",
			"heatLossElementsArea", "volume", "volumeDivHeatLossElemArea",
			"averageUvalueRoofAndFloor" };

	public static final Object[] OUTPUT_INFO_TYPICAL_FLOOR_FORM = new Object[] {
			"facadeOneTypicalFloorArea", "facadeTwoTypicalFloorArea",
			"facadeThreeTypicalFloorArea", "facadeFourTypicalFloorArea",
			"facadeOneTypicalFloorGlazedArea",
			"facadeTwoTypicalFloorGlazedArea",
			"facadeThreeTypicalFloorGlazedArea",
			"facadeFourTypicalFloorGlazedArea",
			"facadeOneTypicalFloorPerimeterZoneArea",
			"facadeTwoTypicalFloorPerimeterZoneArea",
			"facadeThreeTypicalFloorPerimeterZoneArea",
			"facadeFourTypicalFloorPerimeterZoneArea" };

	public static final Object[] WINDOW_SHADING_CONFIGURATION_FORM = new Object[] {
			"windowPercentageFrame", "windowGlazing", "windowShadingType",
			"windowConfig", "windowDepth", "shadingAngle", "louvreColour",
			"slatAngle", "applyToFacadeOne", "applyToFacadeTwo",
			"applyToFacadeThree", "applyToFacadeFour" };
	
	public static final Object[] SURROUNDING_FEATURES_FORM = new Object[] {
		"facadeOneSurroundingFeaturesAverageHeight",
		"facadeOneSurroundingFeaturesAverageDistance",
		"facadeTwoSurroundingFeaturesAverageHeight",
		"facadeTwoSurroundingFeaturesAverageDistance",
		"facadeThreeSurroundingFeaturesAverageHeight",
		"facadeThreeSurroundingFeaturesAverageDistance",
		"facadeFourSurroundingFeaturesAverageHeight",
		"facadeFourSurroundingFeaturesAverageDistance" };
	
	public static final Object[] DAYLIGHTING_INPUTS_FORM = new Object[] {
		"wallThickness", "diffuseTransmittanceText", 
		"averageReflectanceOfInteriorSurfacesText" };
	
	public static final Object[] DAYLIGHTING_GENERAL_INPUT_FORM = new Object[] {
		"wallThickness", "averageReflectanceOfInteriorSurfacesText", "maintenanceFactorValue" };
	
	public static final Object[] DESIGN_DAYLIGHTING_FACTOR_FORM = new Object[] {
		"averageGroundFloorDesignDaylightFactor",
		"averageFirstFloorDesignDaylightFactor",
		"averageSecondFloorDesignDaylightFactor" };
	
	public static final Object[] GLAZING_PERCENTAGE_FORM = new Object[] {
		"facadeOneGlazedPercentageValue", "facadeTwoGlazedPercentageValue",
		"facadeThreeGlazedPercentageValue", "facadeFourGlazedPercentageValue" };
	
	public static final Object[] AVERAGE_DAILY_SOLAR_LOAD_PER_FLOOR_FORM = new Object[] {
		"facadeOneAvgDailySolarLoadPerFloorValue",
		"facadeTwoAvgDailySolarLoadPerFloorValue",
		"facadeThreeAvgDailySolarLoadPerFloorValue",
		"facadeFourAvgDailySolarLoadPerFloorValue" };

	private Window login, mainWindow; //, logout;

	private String remoteAddress;
	private String userAgent;
	
	private static ThreadLocal<FenestraProApplication> threadLocal = new ThreadLocal<FenestraProApplication>();
	
    /**
     * Part of the Thread Local Pattern implementation
     */
    @Override
    public void onRequestStart(HttpServletRequest request, HttpServletResponse response) {
    		FenestraProApplication.setInstance(this);
    }
    
    /**
     * Part of the Thread Local Pattern implementation
     */
    @Override
    public void onRequestEnd(HttpServletRequest request, HttpServletResponse response) {
            threadLocal.remove();
    }

    /**
     * Part of the Thread Local Pattern implementation
     * 
     * Set the current application instance
     * @param application
     */
    private static void setInstance(FenestraProApplication application) {
            if (getInstance() == null) {
                    threadLocal.set(application);
            }
    }
    
    /**
     * Part of the Thread Local Pattern implementation
     * 
     * @return
     */
    public static FenestraProApplication getInstance() {
            return threadLocal.get();
    }
    
	@Override
	public void init() {

		if (enableProxy) {
			System.setProperty("http.proxyHost", "www-proxy.scss.tcd.ie");
			System.setProperty("http.proxyPort", "8080");
		}

		setInstance(this);
		
		WebApplicationContext context = (WebApplicationContext) this.getContext();
		
		context.addTransactionListener(this);
		
		context.getHttpSession().setMaxInactiveInterval(SESSION_TIMEOUT_AFTER);
		
		this.userAgent = context.getBrowser().getBrowserApplication();
		
		screenshot = new Screenshot();
	    screenshot.addListener(this);
	    
		VerticalLayout root = new VerticalLayout();
		root.setMargin(true);
		root.setSizeFull();

		mainWindow = new Window("FenestraPro", root);
		login = new LoginWindow();
		
		HorizontalLayout header = new HorizontalLayout();
		header.setWidth("100%");
		
		root.addComponent(header);
		
		ThemeResource resource = new ThemeResource("img/logo.png");
		Embedded image = new Embedded(null,resource);
		header.addComponent(image);

		header.setComponentAlignment(image, Alignment.TOP_LEFT);
		
		HorizontalLayout bottonContainer = new HorizontalLayout();
		bottonContainer.setSpacing(true);
		//bottonContainer.setMargin(true);
		
		header.addComponent(bottonContainer);
		header.setComponentAlignment(bottonContainer, Alignment.TOP_RIGHT);
		
		Button buttonFeedback = new Button("Submit Feedback", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				displayFeedback();
			}
		});
		
		buttonFeedback.setWidth("200px");
		buttonFeedback.addStyleName(Runo.BUTTON_SMALL);
		
		bottonContainer.addComponent(buttonFeedback);
		
		Button buttonLogout = new Button("Logout", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				database.destroyConnectionPool();
				getMainWindow().getApplication().close();
				System.out.printf("%s | %s | %s | %s | Logout\n",	
						dateFormat.format(new Date()),
						remoteAddress,
						currentUserFirstName,
						currentCompanyName);
			}
		});

		buttonLogout.setWidth("200px");
		buttonLogout.addStyleName(Runo.BUTTON_SMALL);
		
		bottonContainer.addComponent(buttonLogout);
		
		Label vspacer = new Label("");
		vspacer.setHeight("15px");
		root.addComponent(vspacer);

		final HorizontalSplitPanel split = new HorizontalSplitPanel();
		split.setStyleName(Runo.SPLITPANEL_REDUCED);
		split.setSplitPosition(200, Sizeable.UNITS_PIXELS);
		split.setMinSplitPosition(150, Sizeable.UNITS_PIXELS);

		root.addComponent(split);
		root.setExpandRatio(split, 1);
		
		Label vspacer2 = new Label("");
		vspacer2.setHeight("12px");
		root.addComponent(vspacer2);
		
		Label textCopyright = new Label(
				"<div align='center'><span style='font-weight:bold; color: #fff;'>Fenestra</span><span style='color: #00b2d8;'>Pro</span> &copy; <span style='color: #fff;'>Copyright 2013 Phison Ltd. trading as FenestraPro. All rights reserved.</span></div>",
				Label.CONTENT_XHTML);
		textCopyright.addStyleName(Runo.LABEL_SMALL);
		root.addComponent(textCopyright);
		root.setComponentAlignment(textCopyright, Alignment.BOTTOM_CENTER);
		
		left.setSizeFull();
		split.setFirstComponent(left);

		Accordion accordion = new Accordion();
		accordion.setSizeFull();
		left.setContent(accordion);

		accordion.addTab(new Label(""), "Projects");
		accordion.addTab(new Label(""), "Buildings");
		accordion.addTab(new Label(""), "Preferences");

		right.setSizeFull();
		split.setSecondComponent(right);
		split.setLocked(false);

		right.addListener(new TabSheet.SelectedTabChangeListener() {
			public void selectedTabChange(SelectedTabChangeEvent event) {

				TabSheet tabsheet = event.getTabSheet();
		        Tab tab = tabsheet.getTab(tabsheet.getSelectedTab());
		        
		        selectedTabName = tabsheet.getSelectedTab().getCaption();
		        // the project array position is the tab position -1
		        //TODO: find a better way of identifying the array index
		        int index = tabsheet.getTabPosition(tab) - 1;
		        
		        // load the project if it hasn't already been loaded
		        if	(index >= 0 && projectArray[index] == null) {
		        	loadProtectedResources(index, userProjectIDs[index]);
		        }
			}
		});

		mainWindow.addListener(new ResizeListener() {
		    @Override
		    public void windowResized(ResizeEvent e) {
		        System.out.printf("%s | %s | %s | %s | Size:    %s x %s\n",	
        				dateFormat.format(new Date()),
        				remoteAddress,
        				currentUserFirstName,
        				currentCompanyName,
        				e.getWindow().getWidth(),
        				e.getWindow().getHeight());
		        
		    }
		});
		
		//f5 kills session (Vaadin bug)
//		mainWindow.addListener(new Window.CloseListener() {
//            @Override
//            public void windowClose(CloseEvent e) {
//                close();
//                // if you don't invalidate, a malicious user can kill your
//                // server with an out of memory error, because each refresh will
//                // leave an instance in memory
//                ((WebApplicationContext) getContext()).getHttpSession().invalidate();
//           }
//        });
		 
		if (enableLogin) {
			setMainWindow(login);
			setTheme("login");
			
		} else {
			currentUserID = debugUserID;
			currentCompanyID = debugCompanyID;
			loadMainTabs();
			loadProjects();
		}
	}
	
	public void loadProjects() {
		
		setMainWindow(mainWindow);
		setTheme("fenestrapro");
	    
		userProjectIDs = database.getUserProjectIDs(currentUserID);
		
		for (int i = 0; i < userProjectIDs.length; i++) {
			//loadProtectedResources(i, userProjects[i]);
			AbsoluteLayout tempLayout = new AbsoluteLayout();
			tempLayout.setCaption((String) database.getProjectValue(userProjectIDs[i], "name"));
			projectTabArray[i] = right.addTab(tempLayout);
			liveProjects++;
		}
		
		// If there are no projects, create a default one (first login)
		if (userProjectIDs.length == 0) {
			int newProjectID = database.createProject(currentUserID, currentCompanyID);
			AbsoluteLayout tempLayout = new AbsoluteLayout();
			tempLayout.setCaption("");
			projectTabArray[0] = right.addTab(tempLayout);
			loadProtectedResources(liveProjects++, newProjectID);
			right.setSelectedTab(0);
		}
	}
	
	public void loadMainTabs() {
		
		currentUserFirstName = (String) database.getUserValue(currentUserID, "first_name");
		currentUserSecondName = (String) database.getUserValue(currentUserID, "second_name");
		currentCompanyName = (String) database.getCompanyValue(currentCompanyID, "name");
		
		left.setCaption(currentCompanyName);
		
		Tab home = right.addTab(buildHomeTab(), "Home");
		right.setTabPosition(home, 0);
		right.setSelectedTab(0);
		
		System.out.printf("%s | %s | %s | %s | --------------------------\n",	
				dateFormat.format(new Date()),
				remoteAddress,
				currentUserFirstName,
				currentCompanyName);
		
		System.out.printf("%s | %s | %s | %s | Browser: %s\n",	
				dateFormat.format(new Date()),
				remoteAddress,
				currentUserFirstName,
				currentCompanyName,
				userAgent);
	}
	
	public void addLoginHistory() {
		database.addLoginHistory(currentUserID, remoteAddress, userAgent, login.getBrowserWindowWidth(), login.getBrowserWindowHeight());
	}
	
	public void authenticate(String username, String password) throws Exception {
		
		boolean success = false;
		
		try {
			success = database.login(username, password);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		} catch (InvalidKeySpecException e) {
			e.printStackTrace();
		}
		
		if (success && currentUserID == null) {	
			currentUserID = database.getUserID(username);
			currentCompanyID = (Integer) database.getUserValue(currentUserID, "company_id");
			loadMainTabs();
			loadProjects();
			addLoginHistory();
		} else {
			throw new Exception("Invalid Username or Password");
		}
		
	}
	
	private void loadProtectedResources(final int projectNum, int projectID) {
		
		System.out.printf("%s | %s | %s | %s | --------------------------\n",	
				dateFormat.format(new Date()),
				remoteAddress,
				currentUserFirstName,
				currentCompanyName);
		
		System.out.printf("%s | %s | %s | %s | Project Id.: %s\n",	
				dateFormat.format(new Date()),
				remoteAddress,
				currentUserFirstName,
				currentCompanyName,
				projectID);
		
		long begin = System.currentTimeMillis();
		
		debugTiming(begin, "A");
		long prev = System.currentTimeMillis();
		
		ProjectBean projectInstance = new ProjectBean(projectID, database);
		
		debugTiming(prev, "B");
		prev = System.currentTimeMillis();
		
		projectArray[projectNum] = new Project(projectInstance, this);
		
		buildingBeanItemArray[projectNum] = new BeanItem<Project>(projectArray[projectNum]);
		
		formBuilderArray[projectNum] = new FormBuilder(projectArray[projectNum], buildingBeanItemArray[projectNum]);
		
		gridFormBuilderArray[projectNum] = new GridFormBuilder(projectArray[projectNum], buildingBeanItemArray[projectNum]);

		projectArray[projectNum].notifier().addListener(
				projectArray[projectNum].notifier().new ValueChangeListener() {
					@Override
					public void valueChange(Object propertyId) {
						MethodProperty<?> prop = (MethodProperty<?>) buildingBeanItemArray[projectNum]
								.getItemProperty(propertyId);
						prop.fireValueChange();
					}
				});
		
		debugTiming(prev, "C");
		prev = System.currentTimeMillis();
		
		contentLayoutDaylightFacadeOneArray[projectNum] = generateDaylightFacadeContent("One", maxStoreys, projectNum);
		contentLayoutDaylightFacadeTwoArray[projectNum] = generateDaylightFacadeContent("Two", maxStoreys, projectNum);
		contentLayoutDaylightFacadeThreeArray[projectNum] = generateDaylightFacadeContent("Three", maxStoreys, projectNum);
		contentLayoutDaylightFacadeFourArray[projectNum] = generateDaylightFacadeContent("Four", maxStoreys, projectNum);
		
		debugTiming(prev, "D");
		prev = System.currentTimeMillis();
		
		fillDefaultValues(projectNum);
		
		debugTiming(prev, "E");
		prev = System.currentTimeMillis();
		
		int tabposition = projectNum + 1;
		
		right.removeTab(projectTabArray[projectNum]);
		
		projectTabArray[projectNum] = right.addTab(buildProjectTab(projectNum),tabposition);
		//projectTabArray[projectNum].setClosable(true);
		
		debugTiming(prev, "F");
		prev = System.currentTimeMillis();
		
		projectArray[projectNum].enableSaving(true);
		
		right.setSelectedTab(tabposition);
		
		System.out.printf("%s | %s | %s | %s | --------------------------\n",	
				dateFormat.format(new Date()),
				remoteAddress,
				currentUserFirstName,
				currentCompanyName);
		
		debugTiming(begin, " ");

	}
	
	private void debugTiming(long prev, String label) {
		System.out.printf("%s | %s | %s | %s | Load Time: %s %.3f seconds\n",	
				dateFormat.format(new Date()),
				remoteAddress,
				currentUserFirstName,
				currentCompanyName,
				label,
				(System.currentTimeMillis() - prev) / 1000.0);
	}
	
	public void fillDefaultValues(int projectNum) {
		
		long begin = System.currentTimeMillis();
		
		debugTiming(begin, "D1");
		long prev = System.currentTimeMillis();
		
		// reload the values
		//TODO: check if this is necessary
		projectArray[projectNum].loadPersistedValues();
		
		Double savedFacadePerformance = projectArray[projectNum].getSavedFacadePerformance();
		Double savedPercentageGlazing = projectArray[projectNum].getSavedPercentageGlazing();
		
		Double savedFloorToFloor = projectArray[projectNum].getFloorToFloor();
		Double savedFloorToCeiling = projectArray[projectNum].getFloorToCeiling();
		Double savedOverallBuildingHeight = projectArray[projectNum].getOverallBuildingHeight();
		
		Double savedFacadeOneGlazed = projectArray[projectNum].getFacadeOneGlazedPercentage();
		Double savedFacadeTwoGlazed = projectArray[projectNum].getFacadeTwoGlazedPercentage();
		Double savedFacadeThreeGlazed = projectArray[projectNum].getFacadeThreeGlazedPercentage();
		Double savedFacadeFourGlazed = projectArray[projectNum].getFacadeFourGlazedPercentage();
		
		boolean savedFacadeOneGlazedAreaLock = projectArray[projectNum].isFacadeOneGlazedAreaLock();
		boolean savedFacadeTwoGlazedAreaLock = projectArray[projectNum].isFacadeTwoGlazedAreaLock();
		boolean savedFacadeThreeGlazedAreaLock = projectArray[projectNum].isFacadeThreeGlazedAreaLock();
		boolean savedFacadeFourGlazedAreaLock = projectArray[projectNum].isFacadeFourGlazedAreaLock();
		
		projectArray[projectNum].setFacadeOneSolarTransmittance(1.0d);
		projectArray[projectNum].setFacadeOneShadingFactor(1.0d);
		
		projectArray[projectNum].setFacadeTwoSolarTransmittance(1.0d);
		projectArray[projectNum].setFacadeTwoShadingFactor(1.0d);
		
		projectArray[projectNum].setFacadeThreeSolarTransmittance(1.0d);
		projectArray[projectNum].setFacadeThreeShadingFactor(1.0d);
		
		projectArray[projectNum].setFacadeFourSolarTransmittance(1.0d);
		projectArray[projectNum].setFacadeFourShadingFactor(1.0d);
		
		projectArray[projectNum].setUnlockedFacades();
		
		// we need to do this at it sets the solar loads for the facade
		projectArray[projectNum].setOrientation(projectArray[projectNum].getOrientation());
		
		debugTiming(prev, "D2");
		prev = System.currentTimeMillis();
		
		//projectArray[projectNum].setLengthWidth(projectArray[projectNum].getLength(), projectArray[projectNum].getWidth());
		projectArray[projectNum].setLength(projectArray[projectNum].getLength());
		projectArray[projectNum].setWidth(projectArray[projectNum].getWidth());
		
		debugTiming(prev, "D3");
		prev = System.currentTimeMillis();
		
		projectArray[projectNum].setStoreys(projectArray[projectNum].getStoreys());
		projectArray[projectNum].setFloorToFloor(projectArray[projectNum].getFloorToFloor());
		
		debugTiming(prev, "D4");
		prev = System.currentTimeMillis();
		
		projectArray[projectNum].setWallThickness(projectArray[projectNum].getWallThickness());
		
		projectArray[projectNum].setuValueRoof(projectArray[projectNum].getuValueRoof());
		projectArray[projectNum].setuValueGroundFloor(projectArray[projectNum].getuValueGroundFloor());
		projectArray[projectNum].setuValueGlazing(projectArray[projectNum].getuValueGlazing());
		projectArray[projectNum].setuValueWalls(projectArray[projectNum].getuValueWalls());
		
		// must be set before setting facade performance as the below reset that value
		projectArray[projectNum].setFloorToFloor(savedFloorToFloor);
		projectArray[projectNum].setFloorToCeiling(savedFloorToCeiling);
		projectArray[projectNum].setOverallBuildingHeight(savedOverallBuildingHeight);
		
		// these must be set after uValues
		if (savedFacadePerformance != null)
			projectArray[projectNum].setFacadePerformance(savedFacadePerformance);
		
		if (savedPercentageGlazing != null)
			projectArray[projectNum].setPercentageGlazing(savedPercentageGlazing);
		
		debugTiming(prev, "D5");
		prev = System.currentTimeMillis();
		
		// we need to do this so the daylighting chart can draw
		projectArray[projectNum].setMaintenanceFactorValue();
		
		projectArray[projectNum].setBuildingType(projectArray[projectNum].getBuildingType());
		projectArray[projectNum].setFacadeType(projectArray[projectNum].getFacadeType());
		projectArray[projectNum].setLocationSetting(projectArray[projectNum].getLocationSetting());
		
		this.restoreFacadeValues(projectNum);
		
		debugTiming(prev, "D6");
		prev = System.currentTimeMillis();
		
		projectArray[projectNum].setFacadeOneGlazedAreaLock(false);
		projectArray[projectNum].setFacadeTwoGlazedAreaLock(false);
		projectArray[projectNum].setFacadeThreeGlazedAreaLock(false);
		projectArray[projectNum].setFacadeFourGlazedAreaLock(false);
		
		// we must leave one facade unlocked when setting values
		projectArray[projectNum].setFacadeOneGlazedPercentage(savedFacadeOneGlazed);
		
		projectArray[projectNum].setFacadeTwoGlazedPercentage(savedFacadeTwoGlazed);
		projectArray[projectNum].setFacadeTwoGlazedAreaLock(true);
		
		projectArray[projectNum].setFacadeThreeGlazedPercentage(savedFacadeThreeGlazed);
		projectArray[projectNum].setFacadeThreeGlazedAreaLock(true);
		
		projectArray[projectNum].setFacadeFourGlazedPercentage(savedFacadeFourGlazed);
		projectArray[projectNum].setFacadeFourGlazedAreaLock(true);
		
		projectArray[projectNum].setFacadeOneGlazedAreaLock(savedFacadeOneGlazedAreaLock);
		projectArray[projectNum].setFacadeTwoGlazedAreaLock(savedFacadeTwoGlazedAreaLock);
		projectArray[projectNum].setFacadeThreeGlazedAreaLock(savedFacadeThreeGlazedAreaLock);
		projectArray[projectNum].setFacadeFourGlazedAreaLock(savedFacadeFourGlazedAreaLock);
		
	}

	public void restoreFacadeValues(int projectNum) {

		String savedFacadeOneGlazingType = projectArray[projectNum].getFacadeOneGlazingType();
		String savedFacadeTwoGlazingType = projectArray[projectNum].getFacadeTwoGlazingType();
		String savedFacadeThreeGlazingType = projectArray[projectNum].getFacadeThreeGlazingType();
		String savedFacadeFourGlazingType = projectArray[projectNum].getFacadeFourGlazingType();

		String savedFacadeOneGlazingSpec = projectArray[projectNum].getFacadeOneGlazingSpec();
		String savedFacadeTwoGlazingSpec = projectArray[projectNum].getFacadeTwoGlazingSpec();
		String savedFacadeThreeGlazingSpec = projectArray[projectNum].getFacadeThreeGlazingSpec();
		String savedFacadeFourGlazingSpec = projectArray[projectNum].getFacadeFourGlazingSpec();
		
		String savedFacadeOneWindowShadingType = projectArray[projectNum].getFacadeOneWindowShadingType();
		String savedFacadeTwoWindowShadingType = projectArray[projectNum].getFacadeTwoWindowShadingType();
		String savedFacadeThreeWindowShadingType = projectArray[projectNum].getFacadeThreeWindowShadingType();
		String savedFacadeFourWindowShadingType = projectArray[projectNum].getFacadeFourWindowShadingType();
		
		String savedFacadeOneWindowShadingAngle = projectArray[projectNum].getFacadeOneShadingAngle();
		String savedFacadeTwoWindowShadingAngle = projectArray[projectNum].getFacadeTwoShadingAngle();
		String savedFacadeThreeWindowShadingAngle = projectArray[projectNum].getFacadeThreeShadingAngle();
		String savedFacadeFourWindowShadingAngle = projectArray[projectNum].getFacadeFourShadingAngle();
		
		String savedFacadeOneWindowConfig = projectArray[projectNum].getFacadeOneWindowConfig();
		String savedFacadeTwoWindowConfig = projectArray[projectNum].getFacadeTwoWindowConfig();
		String savedFacadeThreeWindowConfig = projectArray[projectNum].getFacadeThreeWindowConfig();
		String savedFacadeFourWindowConfig = projectArray[projectNum].getFacadeFourWindowConfig();
		
		String savedFacadeOneLouvreColour = projectArray[projectNum].getFacadeOneLouvreColour();
		String savedFacadeTwoLouvreColour = projectArray[projectNum].getFacadeTwoLouvreColour();
		String savedFacadeThreeLouvreColour = projectArray[projectNum].getFacadeThreeLouvreColour();
		String savedFacadeFourLouvreColour = projectArray[projectNum].getFacadeFourLouvreColour();
		
		String savedFacadeOneSlatAngle = projectArray[projectNum].getFacadeOneSlatAngle();
		String savedFacadeTwoSlatAngle = projectArray[projectNum].getFacadeTwoSlatAngle();
		String savedFacadeThreeSlatAngle = projectArray[projectNum].getFacadeThreeSlatAngle();
		String savedFacadeFourSlatAngle = projectArray[projectNum].getFacadeFourSlatAngle();
		
		if (savedFacadeOneGlazingType != null)
			projectArray[projectNum].setFacadeOneGlazingType(savedFacadeOneGlazingType);
		
		if (savedFacadeTwoGlazingType != null)
			projectArray[projectNum].setFacadeTwoGlazingType(savedFacadeTwoGlazingType);
		
		if (savedFacadeThreeGlazingType != null)
			projectArray[projectNum].setFacadeThreeGlazingType(savedFacadeThreeGlazingType);
		
		if (savedFacadeFourGlazingType != null)
			projectArray[projectNum].setFacadeFourGlazingType(savedFacadeFourGlazingType);
		
		if (savedFacadeOneGlazingSpec != null)
			projectArray[projectNum].setFacadeOneGlazingSpec(savedFacadeOneGlazingSpec);
		
		if (savedFacadeTwoGlazingSpec != null)
			projectArray[projectNum].setFacadeTwoGlazingSpec(savedFacadeTwoGlazingSpec);
		
		if (savedFacadeThreeGlazingSpec != null)
			projectArray[projectNum].setFacadeThreeGlazingSpec(savedFacadeThreeGlazingSpec);
		
		if (savedFacadeFourGlazingSpec != null)
			projectArray[projectNum].setFacadeFourGlazingSpec(savedFacadeFourGlazingSpec);
		
		if (savedFacadeOneWindowShadingType != null)
			projectArray[projectNum].setFacadeOneWindowShadingType(savedFacadeOneWindowShadingType);
		
		if (savedFacadeTwoWindowShadingType != null)
			projectArray[projectNum].setFacadeTwoWindowShadingType(savedFacadeTwoWindowShadingType);
		
		if (savedFacadeThreeWindowShadingType != null)
			projectArray[projectNum].setFacadeThreeWindowShadingType(savedFacadeThreeWindowShadingType);
		
		if (savedFacadeFourWindowShadingType != null)
			projectArray[projectNum].setFacadeFourWindowShadingType(savedFacadeFourWindowShadingType);
		
		if (savedFacadeOneWindowShadingAngle != null)
			projectArray[projectNum].setFacadeOneShadingAngle(savedFacadeOneWindowShadingAngle);
		
		if (savedFacadeTwoWindowShadingAngle != null)
			projectArray[projectNum].setFacadeTwoShadingAngle(savedFacadeTwoWindowShadingAngle);
		
		if (savedFacadeThreeWindowShadingAngle != null)
			projectArray[projectNum].setFacadeThreeShadingAngle(savedFacadeThreeWindowShadingAngle);
		
		if (savedFacadeFourWindowShadingAngle != null)
			projectArray[projectNum].setFacadeFourShadingAngle(savedFacadeFourWindowShadingAngle);
		
		if (savedFacadeOneWindowConfig != null)
			projectArray[projectNum].setFacadeOneWindowConfig(savedFacadeOneWindowConfig);
		
		if (savedFacadeTwoWindowConfig != null)
			projectArray[projectNum].setFacadeTwoWindowConfig(savedFacadeTwoWindowConfig);
		
		if (savedFacadeThreeWindowConfig != null)
			projectArray[projectNum].setFacadeThreeWindowConfig(savedFacadeThreeWindowConfig);
		
		if (savedFacadeFourWindowConfig != null)
			projectArray[projectNum].setFacadeFourWindowConfig(savedFacadeFourWindowConfig);
		
		if (savedFacadeOneLouvreColour != null)
			projectArray[projectNum].setFacadeOneLouvreColour(savedFacadeOneLouvreColour);
		
		if (savedFacadeTwoLouvreColour != null)
			projectArray[projectNum].setFacadeTwoLouvreColour(savedFacadeTwoLouvreColour);
		
		if (savedFacadeThreeLouvreColour != null)
			projectArray[projectNum].setFacadeThreeLouvreColour(savedFacadeThreeLouvreColour);
		
		if (savedFacadeFourLouvreColour != null)
			projectArray[projectNum].setFacadeFourLouvreColour(savedFacadeFourLouvreColour);
		
		if (savedFacadeOneSlatAngle != null)
			projectArray[projectNum].setFacadeOneSlatAngle(savedFacadeOneSlatAngle);
		
		if (savedFacadeTwoSlatAngle != null)
			projectArray[projectNum].setFacadeTwoSlatAngle(savedFacadeTwoSlatAngle);
		
		if (savedFacadeThreeSlatAngle != null)
			projectArray[projectNum].setFacadeThreeSlatAngle(savedFacadeThreeSlatAngle);
		
		if (savedFacadeFourSlatAngle != null)
			projectArray[projectNum].setFacadeFourSlatAngle(savedFacadeFourSlatAngle);
	}
	
	Layout buildHomeTab() {

		VerticalLayout root = new VerticalLayout();
		root.setSizeFull();
		root.setCaption("Home");

		Panel welcome = new Panel();
		
		welcome.setCaption("Welcome back " + currentUserFirstName);
		
		welcome.setSizeFull();
		welcome.addStyleName(Runo.PANEL_LIGHT);
		root.addComponent(welcome);
		root.setExpandRatio(welcome, 1);

		CssLayout margin = new CssLayout();
		margin.setMargin(true);
		margin.setWidth("100%");
		welcome.setContent(margin);

		HorizontalLayout texts = new HorizontalLayout();
		texts.setSpacing(true);
		texts.setWidth("100%");
		margin.addComponent(texts);

		Label text = new Label(
				"<h2>FenestraPro Restricted Release</h2><p>FenestraPro is a software tool currently in development for architects to design environmentally efficient building facades more cost effectively. It outlines inputs and outputs generated for information and design purposes only.</p><p>As FenestraPro is currently in development, all current users have been invited to use this prototype for early stage trial and demonstrative purposes, for response and opinion on functionality and usability, and to offer direction to develop the software from Prototype, to Beta, to full Version 1.0.</p>",
				Label.CONTENT_XHTML);
		texts.addComponent(text);
		texts.setExpandRatio(text, 1);

		// Spacer
		text = new Label("");
		text.setWidth("20px");
		texts.addComponent(text);

		text = new Label(
				"<h2>Terms of Use</h2><p>Please note that this software is currently at trial and development stage, and access is restricted. This restricted release should therefore only be used for demonstration and information purposes.  The outputs of this restricted release should not be relied upon for any reason whatsoever.  We do not provide any warranty or representations of any kind in relation to the accuracy or completeness of the outputs of this restricted release, and exclude all liability and responsibility for any loss or damage you or any third party may suffer in reliance upon these outputs.  This software should be treated as strictly private and confidential and should not be disclosed, submitted or issued to any third party in any form.</p>",
				Label.CONTENT_XHTML);
		texts.addComponent(text);
		texts.setExpandRatio(text, 1);

		// Spacer
		text = new Label("");
		text.setWidth("20px");
		texts.addComponent(text);

		/*
		text = new Label(
				"<h3>Column Three</h3><p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec sed egestas nisi.</p><p>Duis vitae sapien eros, quis molestie mauris. Vivamus ligula sem, pretium ut convallis et, sagittis et erat.</p>",
				Label.CONTENT_XHTML);
		texts.addComponent(text);
		texts.setExpandRatio(text, 1);
		*/
		
		root.addComponent(new Label("<hr />", Label.CONTENT_XHTML));

		texts = new HorizontalLayout();
		texts.addStyleName(Runo.LAYOUT_DARKER);
		texts.setSpacing(true);
		texts.setWidth("100%");
		texts.setMargin(true);
		root.addComponent(texts);

		final TextField message = new TextField("Notification description");
        
		Button next = new Button("Create New Project", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				if (liveProjects < maxProjects) {
					createProject();
					message.setValue("New Project Created.");
				} else {
					message.setValue("You are limited to " + maxProjects + " projects in this restricted release.");
					
				}
				event.getButton().getWindow().showNotification("", (String) message.getValue());
			}
		});
		
		next.setWidth("100%");
		next.addStyleName(Runo.BUTTON_DEFAULT);
		next.addStyleName(Runo.BUTTON_BIG);
		texts.addComponent(next);
		texts.setComponentAlignment(next, Alignment.BOTTOM_LEFT);
		texts.setExpandRatio(next, 1);

		// Spacer
		text = new Label("");
		text.setWidth("6px");
		texts.addComponent(text);
		
		next = new Button("Contact Customer Support", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				mainWindow.open(new ExternalResource("http://www.fenestrapro.com/contact-us/"),
		                  "_blank");
			}
		});
		
		next.setWidth("100%");
		next.addStyleName(Runo.BUTTON_DEFAULT);
		next.addStyleName(Runo.BUTTON_BIG);
		texts.addComponent(next);
		texts.setComponentAlignment(next, Alignment.BOTTOM_LEFT);
		texts.setExpandRatio(next, 1);

		/*
		// Spacer
		text = new Label("");
		text.setWidth("20px");
		texts.addComponent(text);
		
		next = new Button("Logout", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				database.destroyConnectionPool();
				getMainWindow().getApplication().close();
			}
		});
		
		next.setWidth("100%");
		next.addStyleName(Runo.BUTTON_DEFAULT);
		next.addStyleName(Runo.BUTTON_BIG);
		texts.addComponent(next);
		texts.setComponentAlignment(next, Alignment.BOTTOM_LEFT);
		texts.setExpandRatio(next, 1);
		*/
		return root;
	}

	public void createProject() {
		int newProjectID = database.createProject(currentUserID, currentCompanyID);
		AbsoluteLayout tempLayout = new AbsoluteLayout();
		tempLayout.setCaption("");
		int index = liveProjects;
		projectTabArray[index] = right.addTab(tempLayout);
		loadProtectedResources(index, newProjectID);
		liveProjects++;
		right.setSelectedTab(right.getTab(liveProjects));
	}
	
	ComponentContainer buildProjectTab(int projectNum) {
		
		AbsoluteLayout projectRoot = projectArray[projectNum].getProjectRootLayout();
		tabSheetLeft = new TabSheet();
		tabSheetRight = new TabSheet();
		
		projectRoot.setSizeFull();
		//projectRoot.setCaption("Project Tab " + (projectNum + 1));

		final HorizontalSplitPanel split = new HorizontalSplitPanel();
		split.setSplitPosition(54, Sizeable.UNITS_PERCENTAGE);
		split.setMinSplitPosition(15, Sizeable.UNITS_PERCENTAGE);
		split.setMaxSplitPosition(85, Sizeable.UNITS_PERCENTAGE);

		projectRoot.addComponent(split);

		split.setFirstComponent(tabSheetLeft);

		tabSheetLeft.setSizeFull();
		tabSheetLeft.addStyleName(Runo.TABSHEET_SMALL);
		tabSheetLeft.addTab(buildProjectManagerScreen(projectNum));
		tabSheetLeft.addTab(buildBuildingManagerScreen(projectNum));
		tabSheetLeft.addTab(buildPerformanceManagerScreen(projectNum));
		tabSheetLeft.addTab(buildFacadeManagerScreen(projectNum));
		tabSheetLeft.addTab(buildDaylightManagerScreen(projectNum));
		//exampleProjectLeft.addTab(buildDebugScreen());

		//tabSheetLeft.getTab(2).setEnabled(false);
		
		split.setSecondComponent(tabSheetRight);

		tabSheetRight.setSizeFull();
		tabSheetRight.addStyleName(Runo.TABSHEET_SMALL);
		tabSheetRight.addTab(viewerTabBuilding(projectNum));
		tabSheetRight.addTab(viewerTabGlazing(projectNum));
		tabSheetRight.addTab(viewerTabHeatGain(projectNum));
		tabSheetRight.addTab(viewerTabDaylight(projectNum));
		//tabSheetRight.addTab(viewerReport(projectNum));

		return projectRoot;
	}

	// START LEFT TABS
	
	Layout buildProjectManagerScreen(final int projectNum) {
		
		AbsoluteLayout absRoot = new AbsoluteLayout();
		absRoot.setCaption("Project Manager");
		absRoot.setSizeFull();
		
		VerticalLayout root = new VerticalLayout();
		root.setSizeFull();
		absRoot.addComponent(root);
		
		Panel main = new Panel();
		main.setSizeFull();
		main.addStyleName(Runo.PANEL_LIGHT);
		
		root.addComponent(main);
		root.setExpandRatio(main, 1);

		// Top Button
		/*
		HorizontalLayout buttonContainer = new HorizontalLayout();
		buttonContainer.setSpacing(true);

		Button distributeGlazingFromSolar = new Button("Auto Distribute Glazing");
		distributeGlazingFromSolar.addListener(new ClickListener() {
			public void buttonClick(ClickEvent event) {
				building.setGlazingDistributionFromSolarLoads();
			}
		});

		buttonContainer.addComponent(distributeGlazingFromSolar);
		absRoot.addComponent(buttonContainer, "top: 10px; right: 18px; z-index:1;");
		*/
		
		CssLayout margin = new CssLayout();
		margin.setMargin(true);
		margin.setWidth("100%");
		main.setContent(margin);

		VerticalLayout body = new VerticalLayout();
		body.setWidth("100%");
		body.setSpacing(true);
		margin.addComponent(body);

		Panel panelProjectInformation = new Panel("Project Information");
		VerticalLayout formProjectInfromation = (VerticalLayout) formBuilderArray[projectNum]
				.buildFormLayout(PROJECT_DETAILS_FORM, vertical);
		panelProjectInformation.addComponent(formProjectInfromation);
		body.addComponent(panelProjectInformation);

		Panel panelSiteLocation = new Panel("Site Location");
		AbsoluteLayout rootLayoutSiteLocation = new AbsoluteLayout();
		rootLayoutSiteLocation.setHeight("400px");
		panelSiteLocation.setContent(rootLayoutSiteLocation);
		final GoogleMap googleMap = new GoogleMap(this, new Point2D.Double(projectArray[projectNum].getLongitude(), projectArray[projectNum].getLatitude()), 12);
		final Marker marker = new BasicMarker(1L, new Point2D.Double(projectArray[projectNum].getLongitude(), projectArray[projectNum].getLatitude()), "Site Location");
		googleMap.setSizeFull();
		googleMap.addMarker(marker);
		googleMap.addControl(MapControl.HierarchicalMapTypeControl);
		googleMap.addControl(MapControl.ScaleControl);
		googleMap.addControl(MapControl.SmallMapControl);
		googleMap.addListener(new MarkerMovedListener() {
			@Override
			public void markerMoved(Marker movedMarker) {
				projectArray[projectNum].setGpsLocation(movedMarker.getLatLng());
			}
		});
		rootLayoutSiteLocation.addComponent(googleMap);
		body.addComponent(panelSiteLocation);
		
		root.addComponent(new Label("<hr />", Label.CONTENT_XHTML));

		HorizontalLayout footer = new HorizontalLayout();
		footer.addStyleName(Runo.LAYOUT_DARKER);
		footer.setSpacing(true);
		footer.setMargin(true);
		footer.setWidth("100%");
		
		Button buttonAutoDistributeGlazing = new Button("Auto Distribute Glazing", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				projectArray[projectNum].setGlazingDistributionFromSolarLoads();
				projectArray[projectNum].saveFacadeGlazedPercentages();
			}
		});
		
		buttonAutoDistributeGlazing.setWidth("100%");
		buttonAutoDistributeGlazing.addStyleName(Runo.BUTTON_DEFAULT);
		buttonAutoDistributeGlazing.addStyleName(Runo.BUTTON_BIG);
		
		footer.addComponent(buttonAutoDistributeGlazing);
		footer.setComponentAlignment(buttonAutoDistributeGlazing, Alignment.BOTTOM_LEFT);
		footer.setExpandRatio(buttonAutoDistributeGlazing, 1);
	    
		root.addComponent(footer);

		return absRoot;
	}

	Layout buildBuildingManagerScreen(final int projectNum) {

		AbsoluteLayout absRoot = new AbsoluteLayout();
		absRoot.setCaption("Building Manager");
		absRoot.setSizeFull();
		
		VerticalLayout root = new VerticalLayout();
		root.setSizeFull();
		absRoot.addComponent(root);
		
		Panel main = new Panel();
		main.setSizeFull();
		main.addStyleName(Runo.PANEL_LIGHT);
		
		root.addComponent(main);
		root.setExpandRatio(main, 1);

		// Top Button
		/*
		HorizontalLayout buttonContainer = new HorizontalLayout();
		buttonContainer.setSpacing(true);

		Button distributeGlazingFromSolar = new Button("Auto Distribute Glazing");
		distributeGlazingFromSolar.addListener(new ClickListener() {
			public void buttonClick(ClickEvent event) {
				building.setGlazingDistributionFromSolarLoads();
			}
		});

		buttonContainer.addComponent(distributeGlazingFromSolar);
		absRoot.addComponent(buttonContainer, "top: 10px; right: 18px; z-index:1;");
		*/
		
		CssLayout margin = new CssLayout();
		margin.setMargin(true);
		margin.setWidth("100%");
		main.setContent(margin);

		VerticalLayout body = new VerticalLayout();
		body.setWidth("100%");
		body.setSpacing(true);
		margin.addComponent(body);

		Panel panelProperties = new Panel("Building Geometry");
		VerticalLayout formLayout = (VerticalLayout) formBuilderArray[projectNum]
				.buildFormLayout(BUILDING_MANAGER_FORM, vertical);
		panelProperties.addComponent(formLayout);
		body.addComponent(panelProperties);
		
		Panel panelSiteOrientation = new Panel("Site Orientation");
		VerticalLayout formLayout1 = (VerticalLayout) formBuilderArray[projectNum]
				.buildFormLayout(BUILDING_ORIENTATION_FORM, vertical);
		panelSiteOrientation.addComponent(formLayout1);
		body.addComponent(panelSiteOrientation);

		root.addComponent(new Label("<hr />", Label.CONTENT_XHTML));

		HorizontalLayout footer = new HorizontalLayout();
		footer.addStyleName(Runo.LAYOUT_DARKER);
		footer.setSpacing(true);
		footer.setMargin(true);
		footer.setWidth("100%");
		
		Button buttonAutoDistributeGlazing = new Button("Auto Distribute Glazing", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				projectArray[projectNum].setGlazingDistributionFromSolarLoads();
				projectArray[projectNum].saveFacadeGlazedPercentages();
			}
		});
		
		buttonAutoDistributeGlazing.setWidth("100%");
		buttonAutoDistributeGlazing.addStyleName(Runo.BUTTON_DEFAULT);
		buttonAutoDistributeGlazing.addStyleName(Runo.BUTTON_BIG);
		
		footer.addComponent(buttonAutoDistributeGlazing);
		footer.setComponentAlignment(buttonAutoDistributeGlazing, Alignment.BOTTOM_LEFT);
		footer.setExpandRatio(buttonAutoDistributeGlazing, 1);
	    
		root.addComponent(footer);

		return absRoot;
	}

	Layout buildPerformanceManagerScreen(final int projectNum) {

		AbsoluteLayout absRoot = new AbsoluteLayout();
		absRoot.setCaption("Performance Manager");
		absRoot.setSizeFull();
		
		VerticalLayout root = new VerticalLayout();
		root.setSizeFull();
		absRoot.addComponent(root);
		
		Panel main = new Panel();
		main.setSizeFull();
		main.addStyleName(Runo.PANEL_LIGHT);
		
		root.addComponent(main);
		root.setExpandRatio(main, 1);

		// Top Button
		/*
		HorizontalLayout buttonContainer = new HorizontalLayout();
		buttonContainer.setSpacing(true);

		Button distributeGlazingFromSolar = new Button("Auto Distribute Glazing");
		distributeGlazingFromSolar.addListener(new ClickListener() {
			public void buttonClick(ClickEvent event) {
				building.setGlazingDistributionFromSolarLoads();
			}
		});

		buttonContainer.addComponent(distributeGlazingFromSolar);
		absRoot.addComponent(buttonContainer, "top: 10px; right: 18px; z-index:1;");
		*/
		
		CssLayout margin = new CssLayout();
		margin.setMargin(true);
		margin.setWidth("100%");
		main.setContent(margin);

		VerticalLayout body = new VerticalLayout();
		body.setWidth("100%");
		body.setSpacing(true);
		margin.addComponent(body);
		
		Panel panelOverallPerformanceRequirement = new Panel("Overall Performance Requirement");
		Label lableOverallPerformanceRequirement = new Label("Select the OVERALL thermal performance of the entire fa�ade � this, in conjunction with the elemental U-values below, will determine your glazing : wall ratio.");
		panelOverallPerformanceRequirement.addComponent(lableOverallPerformanceRequirement);
		VerticalLayout formLayout = (VerticalLayout) formBuilderArray[projectNum]
				.buildFormLayout(OVERALL_PERFORMANCE_REQUIREMENT_FORM, vertical);
		panelOverallPerformanceRequirement.addComponent(formLayout);
		body.addComponent(panelOverallPerformanceRequirement);
		
		Panel panelElementalUvalues = new Panel("Thermal Performance Values");
		Label lableElementalUvalues = new Label("Select U-values for the building elements outlined below. The min. and max. values are determined by the selected fa�ade type.");
		panelElementalUvalues.addComponent(lableElementalUvalues);
		VerticalLayout formElementalUvalues = (VerticalLayout) formBuilderArray[projectNum]
				.buildFormLayout(ELEMENTAL_VALUES_FORM, vertical);
		panelElementalUvalues.addComponent(formElementalUvalues);
		body.addComponent(panelElementalUvalues);

		Panel panelOverallPercentageGlazing = new Panel("Overall Percentage Glazing");
		Label lablelOverallPercentageGlazing = new Label("Based on your selected thermal performance values.");
		panelOverallPercentageGlazing.addComponent(lablelOverallPercentageGlazing);
		VerticalLayout formOverallPercentageGlazing = (VerticalLayout) formBuilderArray[projectNum]
				.buildFormLayout(OVERALL_PERCENTAGE_GLAZING_FROM, vertical);
		panelOverallPercentageGlazing.addComponent(formOverallPercentageGlazing);
		body.addComponent(panelOverallPercentageGlazing);
		
		root.addComponent(new Label("<hr />", Label.CONTENT_XHTML));

		HorizontalLayout footer = new HorizontalLayout();
		footer.addStyleName(Runo.LAYOUT_DARKER);
		footer.setSpacing(true);
		footer.setMargin(true);
		footer.setWidth("100%");
		
		Button buttonAutoDistributeGlazing = new Button("Auto Distribute Glazing", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				projectArray[projectNum].setGlazingDistributionFromSolarLoads();
				projectArray[projectNum].saveFacadeGlazedPercentages();
			}
		});
		
		buttonAutoDistributeGlazing.setWidth("100%");
		buttonAutoDistributeGlazing.addStyleName(Runo.BUTTON_DEFAULT);
		buttonAutoDistributeGlazing.addStyleName(Runo.BUTTON_BIG);
		
		footer.addComponent(buttonAutoDistributeGlazing);
		footer.setComponentAlignment(buttonAutoDistributeGlazing, Alignment.BOTTOM_LEFT);
		footer.setExpandRatio(buttonAutoDistributeGlazing, 1);
	    
		root.addComponent(footer);

		return absRoot;
	}

	Layout buildFacadeManagerScreen(final int projectNum) {

		AbsoluteLayout absRoot = new AbsoluteLayout();
		absRoot.setCaption("Fa�ade Manager");
		absRoot.setSizeFull();
		
		VerticalLayout root = new VerticalLayout();
		root.setSizeFull();
		absRoot.addComponent(root);
		
		Panel main = new Panel();
		main.setSizeFull();
		main.addStyleName(Runo.PANEL_LIGHT);
		
		root.addComponent(main);
		root.setExpandRatio(main, 1);

		// Top Button
		/*
		HorizontalLayout buttonContainer = new HorizontalLayout();
		buttonContainer.setSpacing(true);

		Button distributeGlazingFromSolar = new Button("Auto Distribute Glazing");
		distributeGlazingFromSolar.addListener(new ClickListener() {
			public void buttonClick(ClickEvent event) {
				building.setGlazingDistributionFromSolarLoads();
			}
		});

		buttonContainer.addComponent(distributeGlazingFromSolar);
		absRoot.addComponent(buttonContainer, "top: 10px; right: 18px; z-index:1;");
		*/
		
		CssLayout margin = new CssLayout();
		margin.setMargin(true);
		margin.setWidth("100%");
		main.setContent(margin);

		VerticalLayout body = new VerticalLayout();
		body.setWidth("100%");
		body.setSpacing(true);
		margin.addComponent(body);
		
		Panel panelFacadeOne = projectArray[projectNum].getPanelFacadeOne();
		VerticalLayout formPanelFacadeOne = (VerticalLayout) formBuilderArray[projectNum]
				.buildFormLayout(FACADE_ONE_MANAGER_FORM, vertical);
		panelFacadeOne.addComponent(formPanelFacadeOne);
		body.addComponent(panelFacadeOne);
		
		Panel panelFacadeTwo = projectArray[projectNum].getPanelFacadeTwo();
		VerticalLayout formPanelFacadeTwo = (VerticalLayout) formBuilderArray[projectNum]
				.buildFormLayout(FACADE_TWO_MANAGER_FORM, vertical);
		panelFacadeTwo.addComponent(formPanelFacadeTwo);
		body.addComponent(panelFacadeTwo);
		
		Panel panelFacadeThree = projectArray[projectNum].getPanelFacadeThree();
		VerticalLayout formPanelFacadeThree = (VerticalLayout) formBuilderArray[projectNum]
				.buildFormLayout(FACADE_THREE_MANAGER_FORM, vertical);
		panelFacadeThree.addComponent(formPanelFacadeThree);
		body.addComponent(panelFacadeThree);
		
		Panel panelFacadeFour = projectArray[projectNum].getPanelFacadeFour();
		VerticalLayout formPanelFacadeFour = (VerticalLayout) formBuilderArray[projectNum]
				.buildFormLayout(FACADE_FOUR_MANAGER_FORM, vertical);
		panelFacadeFour.addComponent(formPanelFacadeFour);
		body.addComponent(panelFacadeFour);
		
		root.addComponent(new Label("<hr />", Label.CONTENT_XHTML));

		HorizontalLayout footer = new HorizontalLayout();
		footer.addStyleName(Runo.LAYOUT_DARKER);
		footer.setSpacing(true);
		footer.setMargin(true);
		footer.setWidth("100%");
		
		Button buttonAutoDistributeGlazing = new Button("Auto Distribute Glazing", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				projectArray[projectNum].setGlazingDistributionFromSolarLoads();
				projectArray[projectNum].saveFacadeGlazedPercentages();
			}
		});
		
		buttonAutoDistributeGlazing.setWidth("100%");
		buttonAutoDistributeGlazing.addStyleName(Runo.BUTTON_DEFAULT);
		buttonAutoDistributeGlazing.addStyleName(Runo.BUTTON_BIG);
		
		footer.addComponent(buttonAutoDistributeGlazing);
		footer.setComponentAlignment(buttonAutoDistributeGlazing, Alignment.BOTTOM_LEFT);
		footer.setExpandRatio(buttonAutoDistributeGlazing, 1);
	    
		root.addComponent(footer);

		return absRoot;
	}
	
	Layout buildDaylightManagerScreen(final int projectNum) {

		AbsoluteLayout absRoot = new AbsoluteLayout();
		absRoot.setCaption("Daylight Manager");
		absRoot.setSizeFull();
		
		VerticalLayout root = new VerticalLayout();
		root.setSizeFull();
		absRoot.addComponent(root);
		
		Panel main = new Panel();
		main.setSizeFull();
		main.addStyleName(Runo.PANEL_LIGHT);
		
		root.addComponent(main);
		root.setExpandRatio(main, 1);
		
		// Top Button
		/*
		HorizontalLayout buttonContainer = new HorizontalLayout();
		buttonContainer.setSpacing(true);

		Button distributeGlazingFromSolar = new Button("Auto Distribute Glazing");
		distributeGlazingFromSolar.addListener(new ClickListener() {
			public void buttonClick(ClickEvent event) {
				building.setGlazingDistributionFromSolarLoads();
			}
		});

		buttonContainer.addComponent(distributeGlazingFromSolar);
		absRoot.addComponent(buttonContainer, "top: 10px; right: 18px; z-index:1;");
		*/
		
		CssLayout margin = new CssLayout();
		margin.setMargin(true);
		margin.setWidth("100%");
		main.setContent(margin);

		VerticalLayout body = new VerticalLayout();
		body.setWidth("100%");
		body.setSpacing(true);
		margin.addComponent(body);
		
		Panel panelProperties = new Panel("Daylighting Information");
		VerticalLayout formLayout = (VerticalLayout) formBuilderArray[projectNum]
				.buildFormLayout(DAYLIGHTING_GENERAL_INPUT_FORM, vertical);
		panelProperties.addComponent(formLayout);
		body.addComponent(panelProperties);
		
		Panel panelFacadeOne = projectArray[projectNum].getPanelContentDaylightFacadeOne();
		panelFacadeOne.addComponent(contentLayoutDaylightFacadeOneArray[projectNum]);
		body.addComponent(panelFacadeOne);
		
		Panel panelFacadeTwo = projectArray[projectNum].getPanelContentDaylightFacadeTwo();
		panelFacadeTwo.addComponent(contentLayoutDaylightFacadeTwoArray[projectNum]);
		body.addComponent(panelFacadeTwo);

		Panel panelFacadeThree = projectArray[projectNum].getPanelContentDaylightFacadeThree();
		panelFacadeThree.addComponent(contentLayoutDaylightFacadeThreeArray[projectNum]);
		body.addComponent(panelFacadeThree);
		
		Panel panelFacadeFour = projectArray[projectNum].getPanelContentDaylightFacadeFour();
		panelFacadeFour.addComponent(contentLayoutDaylightFacadeFourArray[projectNum]);
		body.addComponent(panelFacadeFour);
		
		root.addComponent(new Label("<hr />", Label.CONTENT_XHTML));

		HorizontalLayout footer = new HorizontalLayout();
		footer.addStyleName(Runo.LAYOUT_DARKER);
		footer.setSpacing(true);
		footer.setMargin(true);
		footer.setWidth("100%");
		
		Button buttonAutoDistributeGlazing = new Button("Auto Distribute Glazing", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				projectArray[projectNum].setGlazingDistributionFromSolarLoads();
				projectArray[projectNum].saveFacadeGlazedPercentages();
			}
		});
		
		buttonAutoDistributeGlazing.setWidth("100%");
		buttonAutoDistributeGlazing.addStyleName(Runo.BUTTON_DEFAULT);
		buttonAutoDistributeGlazing.addStyleName(Runo.BUTTON_BIG);
		
		footer.addComponent(buttonAutoDistributeGlazing);
		footer.setComponentAlignment(buttonAutoDistributeGlazing, Alignment.BOTTOM_LEFT);
		footer.setExpandRatio(buttonAutoDistributeGlazing, 1);
	    
		root.addComponent(footer);

		return absRoot;
	}
	
	public GridLayout generateDaylightFacadeContent(String facadeNum, int floors, final int projectNum) {
		Object[] FACADE_DAYLIGHT_FORM = new Object[] {
			"facade" + facadeNum + "SurroundingFeaturesAverageHeight",
			"facade" + facadeNum + "SurroundingFeaturesAverageDistance"
		};
		
		VerticalLayout layoutSurroundingFeatures = (VerticalLayout) formBuilderArray[projectNum]
				.buildFormLayout(FACADE_DAYLIGHT_FORM, vertical);
		
		Object[] objArrayWindowDimensions = Functions.genWindowDimenstionsObjectArray(facadeNum, floors);
		GridLayout layoutWindowDimensions = (GridLayout) gridFormBuilderArray[projectNum]
				.buildFormLayout(objArrayWindowDimensions, daylightInput);
		
		GridLayout contentLayout = new GridLayout();
		contentLayout.setStyleName("colsfacade");
		contentLayout.setWidth("100%");
		
		Label emptyLabel1 = new Label("");
		emptyLabel1.setHeight("1em");
		
		Label emptyLabel2 = new Label("");
		emptyLabel2.setHeight("2px");
		
		contentLayout.addComponent(new Label("Surrounding Features"));
		contentLayout.addComponent(layoutSurroundingFeatures);
		contentLayout.addComponent(emptyLabel1);
		contentLayout.addComponent(new Label("Window Dimensions"));
		contentLayout.addComponent(emptyLabel2);
		contentLayout.addComponent(layoutWindowDimensions);
		
		return contentLayout;
	}
	
	// END LEFT TABS
	
	// START RIGHT TABS
	
	Layout viewerTabBuilding(final int projectNum) {

		AbsoluteLayout absRoot = new AbsoluteLayout();
		absRoot.setCaption("Building Viewer");
		absRoot.setSizeFull();
		
		VerticalLayout root = new VerticalLayout();
		root.setSizeFull();
		absRoot.addComponent(root);
		
		Panel main = new Panel();
		main.setSizeFull();
		main.addStyleName(Runo.PANEL_LIGHT);
		
		root.addComponent(main);
		root.setExpandRatio(main, 1);

		// Top Button
		/*
		HorizontalLayout buttonContainer = new HorizontalLayout();
		buttonContainer.setSpacing(true);

		Button distributeGlazingFromSolar = new Button("Auto Distribute Glazing");
		distributeGlazingFromSolar.addListener(new ClickListener() {
			public void buttonClick(ClickEvent event) {
				building.setGlazingDistributionFromSolarLoads();
			}
		});

		buttonContainer.addComponent(distributeGlazingFromSolar);
		absRoot.addComponent(buttonContainer, "top: 10px; right: 18px; z-index:1;");
		*/
		
		CssLayout margin = new CssLayout();
		margin.setMargin(true);
		margin.setWidth("100%");
		main.setContent(margin);

		VerticalLayout body = new VerticalLayout();
		body.setWidth("100%");
		body.setSpacing(true);
		margin.addComponent(body);

		Panel panelBuildingOrientation = new Panel("Building Orientation");
		GridLayout orientation = buildBuildingOrientationGrid(projectNum);
		panelBuildingOrientation.addComponent(orientation);
		body.addComponent(panelBuildingOrientation);
		
		root.addComponent(new Label("<hr />", Label.CONTENT_XHTML));

		HorizontalLayout footer = new HorizontalLayout();
		footer.addStyleName(Runo.LAYOUT_DARKER);
		footer.setSpacing(true);
		footer.setMargin(true);
		footer.setWidth("100%");
		
		Button buttonGeneratePDF = new Button("Generate PDF Report", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				displayPopup(projectNum);
			}
		});
		
		buttonGeneratePDF.setWidth("100%");
		buttonGeneratePDF.addStyleName(Runo.BUTTON_DEFAULT);
		buttonGeneratePDF.addStyleName(Runo.BUTTON_BIG);
		
		footer.addComponent(buttonGeneratePDF);
		footer.setComponentAlignment(buttonGeneratePDF, Alignment.BOTTOM_LEFT);
		footer.setExpandRatio(buttonGeneratePDF, 1);
	    
		root.addComponent(footer);

		return absRoot;
	}
	
	Layout viewerTabGlazing(final int projectNum) {

		AbsoluteLayout absRoot = new AbsoluteLayout();
		absRoot.setCaption("Glazing Viewer");
		absRoot.setSizeFull();
		
		VerticalLayout root = new VerticalLayout();
		root.setSizeFull();
		absRoot.addComponent(root);
		
		Panel main = new Panel("");
		main.setSizeFull();
		main.addStyleName(Runo.PANEL_LIGHT);
		
		root.addComponent(main);
		root.setExpandRatio(main, 1);

		// Top Button
		/*
		HorizontalLayout buttonContainer = new HorizontalLayout();
		buttonContainer.setSpacing(true);

		Button distributeGlazingFromSolar = new Button("Auto Distribute Glazing");
		distributeGlazingFromSolar.addListener(new ClickListener() {
			public void buttonClick(ClickEvent event) {
				building.setGlazingDistributionFromSolarLoads();
			}
		});

		buttonContainer.addComponent(distributeGlazingFromSolar);
		absRoot.addComponent(buttonContainer, "top: 10px; right: 18px; z-index:1;");
		*/
		
		CssLayout margin = new CssLayout();
		margin.setMargin(true);
		margin.setWidth("100%");
		main.setContent(margin);

		VerticalLayout body = new VerticalLayout();
		body.setWidth("100%");
		body.setSpacing(true);
		margin.addComponent(body);
        
        Panel panelGlazingPerFacade = new Panel("% Glazing per Facade");
        InvientCharts glazingChart = projectArray[projectNum].getGlazingChart();
        glazingChart.setSizeFull();
        panelGlazingPerFacade.addComponent(glazingChart);
        body.addComponent(panelGlazingPerFacade);
        
		root.addComponent(new Label("<hr />", Label.CONTENT_XHTML));

		HorizontalLayout footer = new HorizontalLayout();
		footer.addStyleName(Runo.LAYOUT_DARKER);
		footer.setSpacing(true);
		footer.setMargin(true);
		footer.setWidth("100%");
		
		Button buttonGeneratePDF = new Button("Generate PDF Report", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				displayPopup(projectNum);
			}
		});
		
		buttonGeneratePDF.setWidth("100%");
		buttonGeneratePDF.addStyleName(Runo.BUTTON_DEFAULT);
		buttonGeneratePDF.addStyleName(Runo.BUTTON_BIG);
		
		footer.addComponent(buttonGeneratePDF);
		footer.setComponentAlignment(buttonGeneratePDF, Alignment.BOTTOM_LEFT);
		footer.setExpandRatio(buttonGeneratePDF, 1);
	    
		root.addComponent(footer);

		return absRoot;
	}
	
	Layout viewerTabHeatGain(final int projectNum) {

		AbsoluteLayout absRoot = new AbsoluteLayout();
		absRoot.setCaption("Heat Gain Viewer");
		absRoot.setSizeFull();
		
		VerticalLayout root = new VerticalLayout();
		root.setSizeFull();
		absRoot.addComponent(root);
		
		Panel main = new Panel("");
		main.setSizeFull();
		main.addStyleName(Runo.PANEL_LIGHT);
		
		root.addComponent(main);
		root.setExpandRatio(main, 1);

		// Top Button
		/*
		HorizontalLayout buttonContainer = new HorizontalLayout();
		buttonContainer.setSpacing(true);

		Button distributeGlazingFromSolar = new Button("Auto Distribute Glazing");
		distributeGlazingFromSolar.addListener(new ClickListener() {
			public void buttonClick(ClickEvent event) {
				building.setGlazingDistributionFromSolarLoads();
			}
		});

		buttonContainer.addComponent(distributeGlazingFromSolar);
		absRoot.addComponent(buttonContainer, "top: 10px; right: 18px; z-index:1;");
		*/
		
		CssLayout margin = new CssLayout();
		margin.setMargin(true);
		margin.setWidth("100%");
		main.setContent(margin);

		VerticalLayout body = new VerticalLayout();
		body.setWidth("100%");
		body.setSpacing(true);
		margin.addComponent(body);
		
		Panel panelHeatGainPerFacade = new Panel("Heat Gain per Fa�ade");	
        InvientCharts heatGainChart = projectArray[projectNum].getHeatGainChart();
        heatGainChart.setSizeFull();
        panelHeatGainPerFacade.addComponent(heatGainChart);
        body.addComponent(panelHeatGainPerFacade);
        
		root.addComponent(new Label("<hr />", Label.CONTENT_XHTML));

		HorizontalLayout footer = new HorizontalLayout();
		footer.addStyleName(Runo.LAYOUT_DARKER);
		footer.setSpacing(true);
		footer.setMargin(true);
		footer.setWidth("100%");
		
		Button buttonGeneratePDF = new Button("Generate PDF Report", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				displayPopup(projectNum);
			}
		});
		
		buttonGeneratePDF.setWidth("100%");
		buttonGeneratePDF.addStyleName(Runo.BUTTON_DEFAULT);
		buttonGeneratePDF.addStyleName(Runo.BUTTON_BIG);
		
		footer.addComponent(buttonGeneratePDF);
		footer.setComponentAlignment(buttonGeneratePDF, Alignment.BOTTOM_LEFT);
		footer.setExpandRatio(buttonGeneratePDF, 1);
	    
		root.addComponent(footer);

		return absRoot;
	}
	
	Layout viewerTabDaylight(final int projectNum) {

		AbsoluteLayout absRoot = new AbsoluteLayout();
		absRoot.setCaption("Daylighting Viewer");
		absRoot.setSizeFull();
		
		VerticalLayout root = new VerticalLayout();
		root.setSizeFull();
		absRoot.addComponent(root);
		
		Panel main = new Panel("");
		main.setSizeFull();
		main.addStyleName(Runo.PANEL_LIGHT);
		
		root.addComponent(main);
		root.setExpandRatio(main, 1);

		// Top Button
		/*
		HorizontalLayout buttonContainer = new HorizontalLayout();
		buttonContainer.setSpacing(true);

		Button distributeGlazingFromSolar = new Button("Auto Distribute Glazing");
		distributeGlazingFromSolar.addListener(new ClickListener() {
			public void buttonClick(ClickEvent event) {
				building.setGlazingDistributionFromSolarLoads();
			}
		});

		buttonContainer.addComponent(distributeGlazingFromSolar);
		absRoot.addComponent(buttonContainer, "top: 10px; right: 18px; z-index:1;");
		*/
		
		CssLayout margin = new CssLayout();
		margin.setMargin(true);
		margin.setWidth("100%");
		main.setContent(margin);

		VerticalLayout body = new VerticalLayout();
		body.setWidth("100%");
		body.setSpacing(true);
		margin.addComponent(body);
		
		Panel daylightingPerFacade = projectArray[projectNum].getDaylightingPerFacade();
        InvientCharts daylightingChart = projectArray[projectNum].getDaylightingChart();
        daylightingChart.setWidth("95%");
        daylightingPerFacade.addComponent(daylightingChart);
        body.addComponent(daylightingPerFacade);

		root.addComponent(new Label("<hr />", Label.CONTENT_XHTML));

		HorizontalLayout footer = new HorizontalLayout();
		footer.addStyleName(Runo.LAYOUT_DARKER);
		footer.setSpacing(true);
		footer.setMargin(true);
		footer.setWidth("100%");
		
		Button buttonGeneratePDF = new Button("Generate PDF Report", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				displayPopup(projectNum);
			}
		});
		
		buttonGeneratePDF.setWidth("100%");
		buttonGeneratePDF.addStyleName(Runo.BUTTON_DEFAULT);
		buttonGeneratePDF.addStyleName(Runo.BUTTON_BIG);
		
		footer.addComponent(buttonGeneratePDF);
		footer.setComponentAlignment(buttonGeneratePDF, Alignment.BOTTOM_LEFT);
		footer.setExpandRatio(buttonGeneratePDF, 1);
	    
		root.addComponent(footer);

		return absRoot;
	}

	/*
	Layout viewerReport(final int projectNum) {

		AbsoluteLayout rooter = new AbsoluteLayout();
		rooter.setCaption("Report View");
		rooter.setSizeFull();
		
		VerticalLayout root = new VerticalLayout();
		root.setSizeFull();

		rooter.addComponent(root);
		
		final Panel main = new Panel("Data Output Report");
		main.setSizeFull();
		main.addStyleName(Runo.PANEL_LIGHT);
		
		root.addComponent(main);
		root.setExpandRatio(main, 1);
		
		HorizontalLayout buttonContainer = new HorizontalLayout();
		buttonContainer.setSpacing(true);
		
		Button generatePDF = new Button("Generate PDF");
		
		generatePDF.addListener(new ClickListener() {

			public void buttonClick(ClickEvent event) {
                displayPopup(projectNum);
			}
		});

        Button updateReport = new Button("Generate Report");
        
		updateReport.addListener(new ClickListener() {

			public void buttonClick(ClickEvent event) {

				event.getButton().addStyleName(Runo.BUTTON_DEFAULT);
				event.getButton().setCaption("Update Report Values");
				CssLayout content = generateReportContent(projectNum);
				main.setContent(content);
			}
		});

		buttonContainer.addComponent(updateReport);
		buttonContainer.addComponent(generatePDF);
		
		rooter.addComponent(buttonContainer, "top: 10px; right: 18px; z-index:1;");
			
		//CssLayout content = generateReportContent();
		//main.setContent(content);
		
		/*
		facadedesigndata_grid.addComponent(new Label("Glazing Distribution per Fa�ade"),0,8);
		facadedesigndata_grid.addComponent(new Label("<b>" + building.getFacadeOneOrientation() + "</b>", Label.CONTENT_XHTML),1,8);
		facadedesigndata_grid.addComponent(new Label(building.getuValueRoof() + UNIT_wm2k),3,8);
		facadedesigndata_grid.addComponent(new Label(""),0,9);
		facadedesigndata_grid.addComponent(new Label("<b>" + building.getFacadeTwoOrientation() + "</b>", Label.CONTENT_XHTML),1,9);
		facadedesigndata_grid.addComponent(new Label(building.getuValueGroundFloor() + UNIT_wm2k),3,9);
		facadedesigndata_grid.addComponent(new Label(""),0,10);
		facadedesigndata_grid.addComponent(new Label("<b>" + building.getFacadeThreeOrientation() + "</b>", Label.CONTENT_XHTML),1,10);
		facadedesigndata_grid.addComponent(new Label(building.getuValueWalls() + UNIT_wm2k),3,10);
		facadedesigndata_grid.addComponent(new Label(""),0,11);
		facadedesigndata_grid.addComponent(new Label("<b>" + building.getFacadeFourOrientation() + "</b>", Label.CONTENT_XHTML),1,11);
		facadedesigndata_grid.addComponent(new Label(building.getuValueWalls() + UNIT_wm2k),3,11);
		*/
		
		/*
		VerticalLayout formLayout = (VerticalLayout) formBuilder
				.buildFormLayout(SOLAR_SHADING_FORM, vertical);
		root.addComponent(formLayout);

		VerticalLayout formLayout1 = (VerticalLayout) formBuilder
				.buildFormLayout(AVERAGE_DAILY_SOLAR_LOAD_PER_FLOOR_FORM, vertical);
		root.addComponent(formLayout1);

		VerticalLayout formLayout2 = (VerticalLayout) formBuilder
				.buildFormLayout(OUTPUT_INFO_TYPICAL_FLOOR_FORM, vertical);
		root.addComponent(formLayout2);

		VerticalLayout formLayout3 = (VerticalLayout) formBuilder
				.buildFormLayout(OUTPUT_INFO_BUILDING_TOTALS_FORM, vertical);
		root.addComponent(formLayout3);
		*/
/*
		return rooter;
	}
*/
	
	// END RIGHT TABS
	/*
	CssLayout generateReportContent(final int projectNum) {
		
		CssLayout margin = new CssLayout();
		
		margin.setMargin(true);
		margin.setWidth("100%");

		Label introduction = new Label("1.0 Introduction");
		introduction.addStyleName(Runo.LABEL_H1);
		margin.addComponent(introduction);

		Label introduction_text = new Label(
				"<p>This report has been produced using <strong>FenestraPro Prototype Version</strong>, a software tool currently in development for architects to design environmentally efficient building facades more cost effectively. It outlines inputs and outputs generated for information and design purposes only.</p>" +
				"<p>As <strong>FenestraPro</strong> is currently in development, all current users have been invited to use as early stage trial and demonstrative purposes, for response and opinion on functionality and usability, and to offer direction to develop the software from Prototype, to Beta, to full Version 1.0.</p>" +
				"<p>The outputs in this report are based on the inputs and specifications provided, and form a coherent record for performance specification at design stage.</p>" +
				"<p><strong>Warning!</strong> Please note that this software is currently at trial and development stage. This report should therefore only be used for demonstration and information purposes. The contents of this report should not be relied upon for any reason whatsoever.  We do not provide any warranty or representations of any kind in relation to the accuracy or completeness of the contents of this report, and exclude all liability and responsibility for any loss or damage you or any third party may suffer in reliance upon this report.  This report should be treated as strictly private and confidential and should not be disclosed, submitted or issued to any third party in any form.</p>",
				Label.CONTENT_XHTML);
		
		margin.addComponent(introduction_text);
		
		Label projectdata = new Label("2.0 Project Data");
		projectdata.addStyleName(Runo.LABEL_H1);
		margin.addComponent(projectdata);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		GridLayout projectdata_grid = new GridLayout(2, 7);
		projectdata_grid.setColumnExpandRatio(0, 2);
		projectdata_grid.setColumnExpandRatio(1, 2);
		projectdata_grid.addStyleName("gridReport");
		projectdata_grid.setWidth("100%");
		   
		projectdata_grid.addComponent(new Label("<b>Name of Project</b>", Label.CONTENT_XHTML));
		projectdata_grid.addComponent(new Label(projectArray[projectNum].getProjName()));
		projectdata_grid.addComponent(new Label("<b>Project Number</b>", Label.CONTENT_XHTML));
		projectdata_grid.addComponent(new Label(projectArray[projectNum].getProjNumber()));
		projectdata_grid.addComponent(new Label("<b>Project Description</b>", Label.CONTENT_XHTML));
		projectdata_grid.addComponent(new Label(projectArray[projectNum].getProjDescription()));
		projectdata_grid.addComponent(new Label("<b>User</b>", Label.CONTENT_XHTML));
		projectdata_grid.addComponent(new Label(currentUserFirstName));
		projectdata_grid.addComponent(new Label("<b>Model Imported</b>", Label.CONTENT_XHTML));
		projectdata_grid.addComponent(new Label("<i>Not available in Restricted Release</i>", Label.CONTENT_XHTML));
		projectdata_grid.addComponent(new Label("<b>Date Generated</b>", Label.CONTENT_XHTML));
		projectdata_grid.addComponent(new Label(dateFormat.format(new Date())));
		projectdata_grid.addComponent(new Label("<b>Report Generated By</b>", Label.CONTENT_XHTML));
		projectdata_grid.addComponent(new Label("FenestraPro Beta v0.1"));
		
		margin.addComponent(projectdata_grid);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		Label buildingdata = new Label("3.0 Building Data");
		buildingdata.addStyleName(Runo.LABEL_H1);
		margin.addComponent(buildingdata);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		GridLayout buildingdata_grid = new GridLayout(2, 4);
		buildingdata_grid.setColumnExpandRatio(0, 2);
		buildingdata_grid.setColumnExpandRatio(1, 2);
		buildingdata_grid.addStyleName("gridReport");
		buildingdata_grid.setWidth("100%");
		   
		buildingdata_grid.addComponent(new Label("<b>Building Type</b>", Label.CONTENT_XHTML));
		buildingdata_grid.addComponent(new Label(projectArray[projectNum].getBuildingType()));
		buildingdata_grid.addComponent(new Label("<b>Fa�ade Type</b>", Label.CONTENT_XHTML));
		buildingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeType()));
		buildingdata_grid.addComponent(new Label("<b>Location</b>", Label.CONTENT_XHTML));
		buildingdata_grid.addComponent(new Label("Lat: " + projectArray[projectNum].getLatitude() + " / Long: " + projectArray[projectNum].getLongitude()));
		buildingdata_grid.addComponent(new Label("<b>Orientation</b>", Label.CONTENT_XHTML));
		buildingdata_grid.addComponent(new Label(projectArray[projectNum].getOrientation()));
		
		margin.addComponent(buildingdata_grid);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		Label buildinggeometrydata = new Label("4.0 Building Geometry Data");
		buildinggeometrydata.addStyleName(Runo.LABEL_H1);
		margin.addComponent(buildinggeometrydata);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		GridLayout buildinggeometrydata_grid = new GridLayout(2, 12);
		buildinggeometrydata_grid.setColumnExpandRatio(0, 2);
		buildinggeometrydata_grid.setColumnExpandRatio(1, 2);
		buildinggeometrydata_grid.addStyleName("gridReport");
		buildinggeometrydata_grid.setWidth("100%");
		   
		buildinggeometrydata_grid.addComponent(new Label("<b>Building Length</b>", Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label(projectArray[projectNum].getLength() + UNIT_m));
		buildinggeometrydata_grid.addComponent(new Label("<b>Building Width</b>", Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label(projectArray[projectNum].getWidth() + UNIT_m));
		buildinggeometrydata_grid.addComponent(new Label("<b>Building Height</b>", Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label(projectArray[projectNum].getOverallBuildingHeight() + UNIT_m));
		buildinggeometrydata_grid.addComponent(new Label("<b>Stories</b>", Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label(projectArray[projectNum].getStoreys() + ""));
		buildinggeometrydata_grid.addComponent(new Label("<b>Floor to Floor Height</b>", Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label(projectArray[projectNum].getFloorToFloor() + UNIT_m));
		buildinggeometrydata_grid.addComponent(new Label("<b>Floor to Ceiling Height</b>", Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label(projectArray[projectNum].getFloorToCeiling() + UNIT_m));
		buildinggeometrydata_grid.addComponent(new Label("<b>Wall Thickness</b>", Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label(projectArray[projectNum].getWallThickness() + UNIT_m));
		buildinggeometrydata_grid.addComponent(new Label("<b>Total Surface Area (At)</b>", Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label(projectArray[projectNum].getHeatLossElementsArea() + UNIT_m2, Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label("<b>Total Wall Area</b>", Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label(projectArray[projectNum].getTotalFacadeArea() + UNIT_m2, Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label("<b>Roof Area</b>", Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label(projectArray[projectNum].getRoofArea() + UNIT_m2, Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label("<b>Footprint Area (Site Coverage)</b>", Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label(projectArray[projectNum].getGroundFloorArea() + UNIT_m2, Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label("<b>Building Volume (V)</b>", Label.CONTENT_XHTML));
		buildinggeometrydata_grid.addComponent(new Label(projectArray[projectNum].getVolume() + UNIT_m3, Label.CONTENT_XHTML));
		
		margin.addComponent(buildinggeometrydata_grid);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		Label thermalperformancedata = new Label("5.0 Thermal Performance Data");
		thermalperformancedata.addStyleName(Runo.LABEL_H1);
		margin.addComponent(thermalperformancedata);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		GridLayout thermalperformancedata_grid = new GridLayout(3, 7);
		thermalperformancedata_grid.setColumnExpandRatio(0, 2);
		thermalperformancedata_grid.setColumnExpandRatio(1, 1);
		thermalperformancedata_grid.setColumnExpandRatio(2, 1);
		thermalperformancedata_grid.addStyleName("gridReport");
		thermalperformancedata_grid.setWidth("100%");
		
		thermalperformancedata_grid.addComponent(new Label("<b>Average Elemental Thermal Performance</b>", Label.CONTENT_XHTML),0,0);
		thermalperformancedata_grid.addComponent(new Label("<b>Roof</b>", Label.CONTENT_XHTML),1,0);
		thermalperformancedata_grid.addComponent(new Label(projectArray[projectNum].getuValueRoof() + UNIT_wm2k),2,0);
		thermalperformancedata_grid.addComponent(new Label(""),0,1);
		thermalperformancedata_grid.addComponent(new Label("<b>Ground Floor</b>", Label.CONTENT_XHTML),1,1);
		thermalperformancedata_grid.addComponent(new Label(projectArray[projectNum].getuValueGroundFloor() + UNIT_wm2k),2,1);
		thermalperformancedata_grid.addComponent(new Label(""),0,2);
		thermalperformancedata_grid.addComponent(new Label("<b>Glazing</b>", Label.CONTENT_XHTML),1,2);
		thermalperformancedata_grid.addComponent(new Label(projectArray[projectNum].getuValueGlazing() + UNIT_wm2k),2,2);
		thermalperformancedata_grid.addComponent(new Label(""),0,3);
		thermalperformancedata_grid.addComponent(new Label("<b>Wall</b>", Label.CONTENT_XHTML),1,3);
		thermalperformancedata_grid.addComponent(new Label(projectArray[projectNum].getuValueWalls() + UNIT_wm2k),2,3);
		thermalperformancedata_grid.addComponent(new Label("<b>Maximum Average U-Value Total</b>", Label.CONTENT_XHTML));
		thermalperformancedata_grid.addComponent(new Label(projectArray[projectNum].getMaxAverageUvalueTotal() + UNIT_wm2k),1,4,2,4);
		thermalperformancedata_grid.addComponent(new Label("<b>Maximum Average U-Value Fa�ade </b>", Label.CONTENT_XHTML));
		thermalperformancedata_grid.addComponent(new Label(projectArray[projectNum].getMaxAverageUvalueFacade() + UNIT_wm2k),1,5,2,5);
		thermalperformancedata_grid.addComponent(new Label("<b>Selected Fa�ade Performance</b>", Label.CONTENT_XHTML));
		thermalperformancedata_grid.addComponent(new Label(projectArray[projectNum].getFacadePerformance() + UNIT_wm2k),1,6,2,6);
		
		margin.addComponent(thermalperformancedata_grid);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		Label facadedesigndata = new Label("6.0 Fa�ade Design Data");
		facadedesigndata.addStyleName(Runo.LABEL_H1);
		margin.addComponent(facadedesigndata);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		GridLayout facadedesigndata_grid = new GridLayout(5, 8);
		facadedesigndata_grid.setColumnExpandRatio(0, 4);
		facadedesigndata_grid.setColumnExpandRatio(1, 1);
		facadedesigndata_grid.setColumnExpandRatio(2, 1);
		facadedesigndata_grid.setColumnExpandRatio(3, 1);
		facadedesigndata_grid.setColumnExpandRatio(4, 1);
		facadedesigndata_grid.addStyleName("gridReport");
		facadedesigndata_grid.setWidth("100%");
		
		facadedesigndata_grid.addComponent(new Label("<b>Total Fa�ade Surface Area</b>", Label.CONTENT_XHTML),0,0);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getTotalFacadeArea() + UNIT_m2, Label.CONTENT_XHTML),1,0,4,0);
		facadedesigndata_grid.addComponent(new Label("<b>Total % Glazing</b>", Label.CONTENT_XHTML),0,1);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getMaxPercentageGlazing() + UNIT_perc),1,1,4,1);
		facadedesigndata_grid.addComponent(new Label("<b>Total Glazed Area</b>", Label.CONTENT_XHTML),0,2);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getTotalGlazedArea() + UNIT_m2, Label.CONTENT_XHTML),1,2,4,2);
		facadedesigndata_grid.addComponent(new Label("<b>Total Wall Area</b>", Label.CONTENT_XHTML),0,3);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getTotalWallArea() + UNIT_m2, Label.CONTENT_XHTML),1,3,4,3);
		facadedesigndata_grid.addComponent(new Label(""),0,4);
		facadedesigndata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeOneOrientation() + "</b>", Label.CONTENT_XHTML),1,4);
		facadedesigndata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeTwoOrientation() + "</b>", Label.CONTENT_XHTML),2,4);
		facadedesigndata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeThreeOrientation() + "</b>", Label.CONTENT_XHTML),3,4);
		facadedesigndata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeFourOrientation() + "</b>", Label.CONTENT_XHTML),4,4);
		facadedesigndata_grid.addComponent(new Label("<b>% Glazing</b>", Label.CONTENT_XHTML),0,5);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneGlazedPercentage() + UNIT_perc),1,5);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoGlazedPercentage() + UNIT_perc),2,5);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeGlazedPercentage() + UNIT_perc),3,5);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourGlazedPercentage() + UNIT_perc),4,5);
		facadedesigndata_grid.addComponent(new Label("<b>Glazed Area</b>", Label.CONTENT_XHTML),0,6);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneGlazedArea() + UNIT_m2, Label.CONTENT_XHTML),1,6);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoGlazedArea() + UNIT_m2, Label.CONTENT_XHTML),2,6);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeGlazedArea() + UNIT_m2, Label.CONTENT_XHTML),3,6);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourGlazedArea() + UNIT_m2, Label.CONTENT_XHTML),4,6);
		facadedesigndata_grid.addComponent(new Label("<b>Wall Area</b>", Label.CONTENT_XHTML),0,7);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneWallArea() + UNIT_m2, Label.CONTENT_XHTML),1,7);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoWallArea() + UNIT_m2, Label.CONTENT_XHTML),2,7);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeWallArea() + UNIT_m2, Label.CONTENT_XHTML),3,7);
		facadedesigndata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourWallArea() + UNIT_m2, Label.CONTENT_XHTML),4,7);

		margin.addComponent(facadedesigndata_grid);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));

		Label shadingdata = new Label("7.0 Shading Data");
		shadingdata.addStyleName(Runo.LABEL_H1);
		margin.addComponent(shadingdata);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		GridLayout shadingdata_grid = new GridLayout(5, 6);
		shadingdata_grid.setColumnExpandRatio(0, 4);
		shadingdata_grid.setColumnExpandRatio(1, 1);
		shadingdata_grid.setColumnExpandRatio(2, 1);
		shadingdata_grid.setColumnExpandRatio(3, 1);
		shadingdata_grid.setColumnExpandRatio(4, 1);
		shadingdata_grid.addStyleName("gridReport");
		shadingdata_grid.setWidth("100%");
		  
		shadingdata_grid.addComponent(new Label(""),0,0);
		shadingdata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeOneOrientation() + "</b>", Label.CONTENT_XHTML),1,0);
		shadingdata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeTwoOrientation() + "</b>", Label.CONTENT_XHTML),2,0);
		shadingdata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeThreeOrientation() + "</b>", Label.CONTENT_XHTML),3,0);
		shadingdata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeFourOrientation() + "</b>", Label.CONTENT_XHTML),4,0);
		shadingdata_grid.addComponent(new Label("<b>Window Configuration Type</b>", Label.CONTENT_XHTML),0,1);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneWindowConfig()),1,1);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoWindowConfig()),2,1);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeWindowConfig()),3,1);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourWindowConfig()),4,1);
		shadingdata_grid.addComponent(new Label("<b>Shading Type</b>", Label.CONTENT_XHTML),0,2);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneWindowShadingType()),1,2);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoWindowShadingType()),2,2);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeWindowShadingType()),3,2);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourWindowShadingType()),4,2);
		shadingdata_grid.addComponent(new Label("<b>Shading Depth</b>", Label.CONTENT_XHTML),0,3);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneWindowShadingDepth() + UNIT_m),1,3);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoWindowShadingDepth() + UNIT_m),2,3);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeWindowShadingDepth() + UNIT_m),3,3);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourWindowShadingDepth() + UNIT_m),4,3);
		shadingdata_grid.addComponent(new Label("<b>Louvre Angle</b>", Label.CONTENT_XHTML),0,4);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneShadingAngle() + UNIT_deg, Label.CONTENT_XHTML),1,4);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoShadingAngle() + UNIT_deg, Label.CONTENT_XHTML),2,4);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeShadingAngle() + UNIT_deg, Label.CONTENT_XHTML),3,4);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourShadingAngle() + UNIT_deg, Label.CONTENT_XHTML),4,4);
		shadingdata_grid.addComponent(new Label("<b>Shading Factor</b>", Label.CONTENT_XHTML),0,5);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneShadingFactor() + ""),1,5);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoShadingFactor() + ""),2,5);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeShadingFactor() + ""),3,5);
		shadingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourShadingFactor() + ""),4,5);
		
		margin.addComponent(shadingdata_grid);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		Label glazingdata = new Label("8.0 Glazing Data");
		glazingdata.addStyleName(Runo.LABEL_H1);
		margin.addComponent(glazingdata);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		GridLayout glazingdata_grid = new GridLayout(6, 1);
		glazingdata_grid.setColumnExpandRatio(0, 2);
		glazingdata_grid.setColumnExpandRatio(1, 2);
		glazingdata_grid.setColumnExpandRatio(2, 1);
		glazingdata_grid.setColumnExpandRatio(3, 1);
		glazingdata_grid.setColumnExpandRatio(4, 1);
		glazingdata_grid.setColumnExpandRatio(5, 1);
		glazingdata_grid.addStyleName("gridReport");
		glazingdata_grid.setWidth("100%");
		   
		glazingdata_grid.addComponent(new Label("<b>Window Heights/Floor</b>", Label.CONTENT_XHTML),0,0,1,0);
		glazingdata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeOneOrientation() + "</b>", Label.CONTENT_XHTML),2,0);
		glazingdata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeTwoOrientation() + "</b>", Label.CONTENT_XHTML),3,0);
		glazingdata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeThreeOrientation() + "</b>", Label.CONTENT_XHTML),4,0);
		glazingdata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeFourOrientation() + "</b>", Label.CONTENT_XHTML),5,0);
		
		int i = 0, j = 0;
		for (i = 0; i < 3; i++) {
			j++;
			glazingdata_grid.setRows(glazingdata_grid.getRows()+3);
			glazingdata_grid.addComponent(new Label("<b>" + floorNames[i] + "</b>", Label.CONTENT_XHTML),0,j);
			glazingdata_grid.addComponent(new Label("Head", Label.CONTENT_XHTML),1,j);
			glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneWindowHH()[i] + UNIT_m),2,j);
			glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoWindowHH()[i] + UNIT_m),3,j);
			glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeWindowHH()[i] + UNIT_m),4,j);
			glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourWindowHH()[i] + UNIT_m),5,j);
			j++;
			glazingdata_grid.addComponent(new Label(""),0,j);
			glazingdata_grid.addComponent(new Label("Cill", Label.CONTENT_XHTML),1,j);
			glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneWindowCH()[i] + UNIT_m),2,j);
			glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoWindowCH()[i] + UNIT_m),3,j);
			glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeWindowCH()[i] + UNIT_m),4,j);
			glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourWindowCH()[i] + UNIT_m),5,j);
			j++;
			glazingdata_grid.addComponent(new Label(""),0,j);
			glazingdata_grid.addComponent(new Label("Reveal", Label.CONTENT_XHTML),1,j);
			glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneWindowRV()[i] + UNIT_m),2,j);
			glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoWindowRV()[i] + UNIT_m),3,j);
			glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeWindowRV()[i] + UNIT_m),4,j);
			glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourWindowRV()[i] + UNIT_m),5,j);
		}
		
		glazingdata_grid.setRows(glazingdata_grid.getRows()+4);
		glazingdata_grid.addComponent(new Label("<b>% Frame</b>", Label.CONTENT_XHTML),0,j+1,1,j+1);
		glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOnePercentageFrame() + UNIT_perc),2,j+1);
		glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoPercentageFrame() + UNIT_perc),3,j+1);
		glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreePercentageFrame() + UNIT_perc),4,j+1);
		glazingdata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourPercentageFrame() + UNIT_perc),5,j+1);
		glazingdata_grid.addComponent(new Label("<b>Diffuse Transmittance</b>", Label.CONTENT_XHTML),0,j+2,1,j+2);
		glazingdata_grid.addComponent(new Label(projectArray[projectNum].getDiffuseTransmittanceText() + "", Label.CONTENT_XHTML),2,j+2,5,j+2);
		glazingdata_grid.addComponent(new Label("<b>Maintenance Factor</b>", Label.CONTENT_XHTML),0,j+3,1,j+3);
		glazingdata_grid.addComponent(new Label(projectArray[projectNum].getMaintenanceFactorValue() + "", Label.CONTENT_XHTML),2,j+3,5,j+3);
		glazingdata_grid.addComponent(new Label("<b>Average Reflectance of Internal Surfaces</b>", Label.CONTENT_XHTML),0,j+4,1,j+4);
		glazingdata_grid.addComponent(new Label(projectArray[projectNum].getAverageReflectanceOfInteriorSurfacesText() + "", Label.CONTENT_XHTML),2,j+4,5,j+4);
		
		margin.addComponent(glazingdata_grid);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		Label typicalfloordata = new Label("9.0 Typical Floor Data");
		typicalfloordata.addStyleName(Runo.LABEL_H1);
		margin.addComponent(typicalfloordata);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		GridLayout typicalfloordata_grid = new GridLayout(5, 8);
		typicalfloordata_grid.setColumnExpandRatio(0, 4);
		typicalfloordata_grid.setColumnExpandRatio(1, 1);
		typicalfloordata_grid.setColumnExpandRatio(2, 1);
		typicalfloordata_grid.setColumnExpandRatio(3, 1);
		typicalfloordata_grid.setColumnExpandRatio(4, 1);
		typicalfloordata_grid.addStyleName("gridReport");
		typicalfloordata_grid.setWidth("100%");
		
		typicalfloordata_grid.addComponent(new Label("<b>Internal Floor Area</b>", Label.CONTENT_XHTML),0,0);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getInternalFloorArea() + UNIT_m2, Label.CONTENT_XHTML),1,0,4,0);
		typicalfloordata_grid.addComponent(new Label("<b>Internal Ceiling Area</b>", Label.CONTENT_XHTML),0,1);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getInternalCeilingArea() + UNIT_m2, Label.CONTENT_XHTML),1,1,4,1);
		typicalfloordata_grid.addComponent(new Label(""),0,2);
		typicalfloordata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeOneOrientation() + "</b>", Label.CONTENT_XHTML),1,2);
		typicalfloordata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeTwoOrientation() + "</b>", Label.CONTENT_XHTML),2,2);
		typicalfloordata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeThreeOrientation() + "</b>", Label.CONTENT_XHTML),3,2);
		typicalfloordata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeFourOrientation() + "</b>", Label.CONTENT_XHTML),4,2);
		typicalfloordata_grid.addComponent(new Label("<b>Area Fa�ade/Floor</b>", Label.CONTENT_XHTML),0,3);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneTypicalFloorArea() + UNIT_m2, Label.CONTENT_XHTML),1,3);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoTypicalFloorArea() + UNIT_m2, Label.CONTENT_XHTML),2,3);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeTypicalFloorArea() + UNIT_m2, Label.CONTENT_XHTML),3,3);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourTypicalFloorArea() + UNIT_m2, Label.CONTENT_XHTML),4,3);
		typicalfloordata_grid.addComponent(new Label("<b>Glazed Area/Floor</b>", Label.CONTENT_XHTML),0,4);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneTypicalFloorGlazedArea() + UNIT_m2, Label.CONTENT_XHTML),1,4);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoTypicalFloorGlazedArea() + UNIT_m2, Label.CONTENT_XHTML),2,4);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeTypicalFloorGlazedArea() + UNIT_m2, Label.CONTENT_XHTML),3,4);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourTypicalFloorGlazedArea() + UNIT_m2, Label.CONTENT_XHTML),4,4);
		typicalfloordata_grid.addComponent(new Label("<b>Extent of Perimeter Zone</b>", Label.CONTENT_XHTML),0,5);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getExtentOfPerimeterZone() + UNIT_m2, Label.CONTENT_XHTML),1,5,4,5);
		typicalfloordata_grid.addComponent(new Label(""),0,6);
		typicalfloordata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeOneOrientation() + "</b>", Label.CONTENT_XHTML),1,6);
		typicalfloordata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeTwoOrientation() + "</b>", Label.CONTENT_XHTML),2,6);
		typicalfloordata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeThreeOrientation() + "</b>", Label.CONTENT_XHTML),3,6);
		typicalfloordata_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeFourOrientation() + "</b>", Label.CONTENT_XHTML),4,6);
		typicalfloordata_grid.addComponent(new Label("<b>Area Perimeter Zones</b>", Label.CONTENT_XHTML),0,7);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneTypicalFloorPerimeterZoneArea() + UNIT_m2, Label.CONTENT_XHTML),1,7);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoTypicalFloorPerimeterZoneArea() + UNIT_m2, Label.CONTENT_XHTML),2,7);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeTypicalFloorPerimeterZoneArea() + UNIT_m2, Label.CONTENT_XHTML),3,7);
		typicalfloordata_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourTypicalFloorPerimeterZoneArea() + UNIT_m2, Label.CONTENT_XHTML),4,7);

		margin.addComponent(typicalfloordata_grid);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		Label facadedesignsummary = new Label("10.0 Fa�ade Design Summary");
		facadedesignsummary.addStyleName(Runo.LABEL_H1);
		margin.addComponent(facadedesignsummary);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		GridLayout facadedesignsummary_grid = new GridLayout(5, 8);
		facadedesignsummary_grid.setColumnExpandRatio(0, 4);
		facadedesignsummary_grid.setColumnExpandRatio(1, 1);
		facadedesignsummary_grid.setColumnExpandRatio(2, 1);
		facadedesignsummary_grid.setColumnExpandRatio(3, 1);
		facadedesignsummary_grid.setColumnExpandRatio(4, 1);
		facadedesignsummary_grid.addStyleName("gridReport");
		facadedesignsummary_grid.setWidth("100%");
		   
		facadedesignsummary_grid.addComponent(new Label("<b>Total Surface Area</b>", Label.CONTENT_XHTML),0,1);
		facadedesignsummary_grid.addComponent(new Label(projectArray[projectNum].getTotalFacadeArea() + UNIT_m2, Label.CONTENT_XHTML),1,1,4,1);
		facadedesignsummary_grid.addComponent(new Label("<b>Total % Glazing</b>", Label.CONTENT_XHTML),0,2);
		facadedesignsummary_grid.addComponent(new Label(projectArray[projectNum].getMaxPercentageGlazing() + UNIT_perc),1,2,4,2);
		facadedesignsummary_grid.addComponent(new Label("<b>Total Glazed Area</b>", Label.CONTENT_XHTML),0,3);
		facadedesignsummary_grid.addComponent(new Label(projectArray[projectNum].getTotalGlazedArea() + UNIT_m2, Label.CONTENT_XHTML),1,3,4,3);
		facadedesignsummary_grid.addComponent(new Label("<b>Total Wall Area</b>", Label.CONTENT_XHTML),0,4);
		facadedesignsummary_grid.addComponent(new Label(projectArray[projectNum].getTotalWallArea() + UNIT_m2, Label.CONTENT_XHTML),1,4,4,4);
		facadedesignsummary_grid.addComponent(new Label(""),0,5);
		facadedesignsummary_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeOneOrientation() + "</b>", Label.CONTENT_XHTML),1,5);
		facadedesignsummary_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeTwoOrientation() + "</b>", Label.CONTENT_XHTML),2,5);
		facadedesignsummary_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeThreeOrientation() + "</b>", Label.CONTENT_XHTML),3,5);
		facadedesignsummary_grid.addComponent(new Label("<b>" + projectArray[projectNum].getFacadeFourOrientation() + "</b>", Label.CONTENT_XHTML),4,5);
		facadedesignsummary_grid.addComponent(new Label("<b>Glazing Distribution</b>", Label.CONTENT_XHTML),0,6);
		facadedesignsummary_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneGlazedPercentage() + UNIT_perc),1,6);
		facadedesignsummary_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoGlazedPercentage() + UNIT_perc),2,6);
		facadedesignsummary_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeGlazedPercentage() + UNIT_perc),3,6);
		facadedesignsummary_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourGlazedPercentage() + UNIT_perc),4,6);
		facadedesignsummary_grid.addComponent(new Label("<b>Solar Load Per Unit Floor Area</b>", Label.CONTENT_XHTML),0,7);
		facadedesignsummary_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneAvgDailySolarLoadPerFloor() + UNIT_wm2),1,7);
		facadedesignsummary_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoAvgDailySolarLoadPerFloor() + UNIT_wm2),2,7);
		facadedesignsummary_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeAvgDailySolarLoadPerFloor() + UNIT_wm2),3,7);
		facadedesignsummary_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourAvgDailySolarLoadPerFloor() + UNIT_wm2),4,7);
		
		margin.addComponent(facadedesignsummary_grid);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		Label facadeonedata = new Label("10.1 " + projectArray[projectNum].getFacadeOneOrientation() + " Fa�ade Summary");
		facadeonedata.addStyleName(Runo.LABEL_H1);
		margin.addComponent(facadeonedata);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		GridLayout facadeonedata_grid = new GridLayout(2, 15);
		facadeonedata_grid.setColumnExpandRatio(0, 2);
		facadeonedata_grid.setColumnExpandRatio(1, 2);
		facadeonedata_grid.addStyleName("gridReport");
		facadeonedata_grid.setWidth("100%");
		   
		facadeonedata_grid.addComponent(new Label("<b>Surface Area</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneArea() + UNIT_m2, Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label("<b>Wall Area</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneWallArea() + UNIT_m2, Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label("<b>Glazed Area</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneGlazedArea() + UNIT_m2, Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label("<b>% Glazed</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneGlazedPercentage() + UNIT_perc, Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label("<b>% Frame</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOnePercentageFrame() + UNIT_perc, Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label("<b>Shading Type</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneWindowShadingType() + "", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label("<b>Shading Depth</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneWindowShadingDepth() + UNIT_m, Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label("<b>Louvre Angle</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneShadingAngle() + UNIT_deg, Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label("<b>Shading Factor</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneShadingFactor() + "", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label("<b>Solar Load Per Unit Floor Area</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneAvgDailySolarLoadPerFloor() + UNIT_wm2));
		facadeonedata_grid.addComponent(new Label("<b>Diffuse Transmittance</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneDiffuseTransmittanceValue() + "", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label("<b>Average Reflectance of Internal Surfaces</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneAverageReflectanceOfInteriorSurfacesValue() + "", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label("<b>Ground Floor Design Daylight Factor</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneAverageDesignDaylightFactor(0) + "", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label("<b>First Floor Design Daylight Factor</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneAverageDesignDaylightFactor(1) + "", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label("<b>Second Floor Design Daylight Factor</b>", Label.CONTENT_XHTML));
		facadeonedata_grid.addComponent(new Label(projectArray[projectNum].getFacadeOneAverageDesignDaylightFactor(2) + "", Label.CONTENT_XHTML));
		
		margin.addComponent(facadeonedata_grid);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		Label facadeTwoData = new Label("10.2 " + projectArray[projectNum].getFacadeTwoOrientation() + " Fa�ade Summary");
		facadeTwoData.addStyleName(Runo.LABEL_H1);
		margin.addComponent(facadeTwoData);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		GridLayout facadeTwoData_grid = new GridLayout(2, 15);
		facadeTwoData_grid.setColumnExpandRatio(0, 2);
		facadeTwoData_grid.setColumnExpandRatio(1, 2);
		facadeTwoData_grid.addStyleName("gridReport");
		facadeTwoData_grid.setWidth("100%");
		   
		facadeTwoData_grid.addComponent(new Label("<b>Surface Area</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoArea() + UNIT_m2, Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label("<b>Wall Area</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoWallArea() + UNIT_m2, Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label("<b>Glazed Area</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoGlazedArea() + UNIT_m2, Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label("<b>% Glazed</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoGlazedPercentage() + UNIT_perc, Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label("<b>% Frame</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoPercentageFrame() + UNIT_perc, Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label("<b>Shading Type</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoWindowShadingType() + "", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label("<b>Shading Depth</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoWindowShadingDepth() + UNIT_m, Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label("<b>Louvre Angle</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoShadingAngle() + UNIT_deg, Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label("<b>Shading Factor</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoShadingFactor() + "", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label("<b>Solar Load Per Unit Floor Area</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoAvgDailySolarLoadPerFloor() + UNIT_wm2));
		facadeTwoData_grid.addComponent(new Label("<b>Diffuse Transmittance</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoDiffuseTransmittanceValue() + "", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label("<b>Average Reflectance of Internal Surfaces</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoAverageReflectanceOfInteriorSurfacesValue() + "", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label("<b>Ground Floor Design Daylight Factor</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoAverageDesignDaylightFactor(0) + "", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label("<b>First Floor Design Daylight Factor</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoAverageDesignDaylightFactor(1) + "", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label("<b>Second Floor Design Daylight Factor</b>", Label.CONTENT_XHTML));
		facadeTwoData_grid.addComponent(new Label(projectArray[projectNum].getFacadeTwoAverageDesignDaylightFactor(2) + "", Label.CONTENT_XHTML));
		
		margin.addComponent(facadeTwoData_grid);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		Label facadeThreeData = new Label("10.3 " + projectArray[projectNum].getFacadeThreeOrientation() + " Fa�ade Summary");
		facadeThreeData.addStyleName(Runo.LABEL_H1);
		margin.addComponent(facadeThreeData);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		GridLayout facadeThreeData_grid = new GridLayout(2, 15);
		facadeThreeData_grid.setColumnExpandRatio(0, 2);
		facadeThreeData_grid.setColumnExpandRatio(1, 2);
		facadeThreeData_grid.addStyleName("gridReport");
		facadeThreeData_grid.setWidth("100%");
		   
		facadeThreeData_grid.addComponent(new Label("<b>Surface Area</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeArea() + UNIT_m2, Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label("<b>Wall Area</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeWallArea() + UNIT_m2, Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label("<b>Glazed Area</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeGlazedArea() + UNIT_m2, Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label("<b>% Glazed</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeGlazedPercentage() + UNIT_perc, Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label("<b>% Frame</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreePercentageFrame() + UNIT_perc, Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label("<b>Shading Type</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeWindowShadingType() + "", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label("<b>Shading Depth</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeWindowShadingDepth() + UNIT_m, Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label("<b>Louvre Angle</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeShadingAngle() + UNIT_deg, Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label("<b>Shading Factor</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeShadingFactor() + "", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label("<b>Solar Load Per Unit Floor Area</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeAvgDailySolarLoadPerFloor() + UNIT_wm2));
		facadeThreeData_grid.addComponent(new Label("<b>Diffuse Transmittance</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeDiffuseTransmittanceValue() + "", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label("<b>Average Reflectance of Internal Surfaces</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeAverageReflectanceOfInteriorSurfacesValue() + "", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label("<b>Ground Floor Design Daylight Factor</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeAverageDesignDaylightFactor(0) + "", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label("<b>First Floor Design Daylight Factor</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeAverageDesignDaylightFactor(1) + "", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label("<b>Second Floor Design Daylight Factor</b>", Label.CONTENT_XHTML));
		facadeThreeData_grid.addComponent(new Label(projectArray[projectNum].getFacadeThreeAverageDesignDaylightFactor(2) + "", Label.CONTENT_XHTML));
		
		margin.addComponent(facadeThreeData_grid);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		Label facadeFourData = new Label("10.4 " + projectArray[projectNum].getFacadeFourOrientation() + " Fa�ade Summary");
		facadeFourData.addStyleName(Runo.LABEL_H1);
		margin.addComponent(facadeFourData);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		GridLayout facadeFourData_grid = new GridLayout(2, 15);
		facadeFourData_grid.setColumnExpandRatio(0, 2);
		facadeFourData_grid.setColumnExpandRatio(1, 2);
		facadeFourData_grid.addStyleName("gridReport");
		facadeFourData_grid.setWidth("100%");
		   
		facadeFourData_grid.addComponent(new Label("<b>Surface Area</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourArea() + UNIT_m2, Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label("<b>Wall Area</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourWallArea() + UNIT_m2, Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label("<b>Glazed Area</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourGlazedArea() + UNIT_m2, Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label("<b>% Glazed</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourGlazedPercentage() + UNIT_perc, Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label("<b>% Frame</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourPercentageFrame() + UNIT_perc, Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label("<b>Shading Type</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourWindowShadingType() + "", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label("<b>Shading Depth</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourWindowShadingDepth() + UNIT_m, Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label("<b>Louvre Angle</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourShadingAngle() + UNIT_deg, Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label("<b>Shading Factor</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourShadingFactor() + "", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label("<b>Solar Load Per Unit Floor Area</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourAvgDailySolarLoadPerFloor() + UNIT_wm2));
		facadeFourData_grid.addComponent(new Label("<b>Diffuse Transmittance</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourDiffuseTransmittanceValue() + "", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label("<b>Average Reflectance of Internal Surfaces</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourAverageReflectanceOfInteriorSurfacesValue() + "", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label("<b>Ground Floor Design Daylight Factor</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourAverageDesignDaylightFactor(0) + "", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label("<b>First Floor Design Daylight Factor</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourAverageDesignDaylightFactor(1) + "", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label("<b>Second Floor Design Daylight Factor</b>", Label.CONTENT_XHTML));
		facadeFourData_grid.addComponent(new Label(projectArray[projectNum].getFacadeFourAverageDesignDaylightFactor(2) + "", Label.CONTENT_XHTML));
		
		margin.addComponent(facadeFourData_grid);
		margin.addComponent(new Label("<br/>", Label.CONTENT_XHTML));
		
		return margin;
	}
	*/
	
	GridLayout buildBuildingOrientationGrid(final int projectNum) {

		GridLayout canvasGrid = new GridLayout(9, 9);
		canvasGrid.addStyleName("gridDir");

		canvasGrid.setWidth("100%");
		canvasGrid.setColumnExpandRatio(0, 5);
		canvasGrid.setColumnExpandRatio(1, 0);
		canvasGrid.setColumnExpandRatio(2, 5);
		canvasGrid.setRowExpandRatio(0, 5);
		canvasGrid.setRowExpandRatio(1, 0);
		canvasGrid.setRowExpandRatio(2, 5);

		Label dirNorthWest = new Label("N-W");
		Label dirNorth = new Label("North");
		Label dirNorthEast = new Label("N-E");
		Label dirEast = new Label("East");
		dirEast.addStyleName("dirside");
		dirEast.setSizeFull();
		Label dirSoutEast = new Label("S-E");
		Label dirSouth = new Label("South");
		Label dirSoutWest = new Label("S-W");
		Label dirWest = new Label("West");
		dirWest.addStyleName("dirside");
		dirWest.setSizeFull();

		canvasGrid.addComponent(dirNorthWest, 0, 0, 0, 0);
		canvasGrid.addComponent(dirNorth, 1, 0, 1, 0);
		canvasGrid.addComponent(dirNorthEast, 2, 0, 2, 0);
		canvasGrid.addComponent(dirWest, 0, 1, 0, 1);
		canvasGrid.addComponent(projectArray[projectNum].canvas(), 1, 1, 1, 1);
		canvasGrid.addComponent(dirEast, 2, 1, 2, 1);
		canvasGrid.addComponent(dirSoutWest, 0, 2, 0, 2);
		canvasGrid.addComponent(dirSouth, 1, 2, 1, 2);
		canvasGrid.addComponent(dirSoutEast, 2, 2, 2, 2);

		return canvasGrid;
	}
	
	/*
	Layout buildDebugScreen() {

		AbsoluteLayout rooter = new AbsoluteLayout();
		rooter.setCaption("Debug");
		rooter.setSizeFull();
		
		VerticalLayout root = new VerticalLayout();
		root.setSizeFull();
		root.setCaption("Test");

		rooter.addComponent(root);
		
		Panel main = new Panel("Debugging Panel");
		main.setSizeFull();
		main.addStyleName(Runo.PANEL_LIGHT);
		
		root.addComponent(main);
		root.setExpandRatio(main, 1);

		HorizontalLayout buttonContainer = new HorizontalLayout();
		
		buttonContainer.setSpacing(true);

		Button testValues = new Button("Set Default Values");

		testValues.addListener(new ClickListener() {

			boolean boolTestValuesClicked = false;

			public void buttonClick(ClickEvent event) {

				boolTestValuesClicked = !boolTestValuesClicked;

				if (boolTestValuesClicked) {

					projectArray[0].setFacadeType("New Build");
					projectArray[0].setBuildingType("Office");

					projectArray[0].setLength(20);
					projectArray[0].setWidth(12);
					projectArray[0].setStoreys(3);
					projectArray[0].setFloorToFloor(3);
					projectArray[0].setWallThickness(0.3);

					projectArray[0].setOrientation(NS);

					projectArray[0].setuValueRoof(0.2d);
					projectArray[0].setuValueGroundFloor(0.3d);
					projectArray[0].setuValueGlazing(1.5);
					projectArray[0].setuValueWalls(0.2d);

					event.getButton().setCaption("Clear Test Values");
					event.getButton().addStyleName(Runo.BUTTON_DEFAULT);

				} else {

					projectArray[0].setFacadeType(null);
					projectArray[0].setBuildingType(null);

					projectArray[0].setLength(0);
					projectArray[0].setWidth(0);
					projectArray[0].setFloorToFloor(0);
					projectArray[0].setStoreys(0);
					projectArray[0].setWallThickness(0);
					projectArray[0].setFloorToCeiling(0);

					//building.setOrientation(null);
					
					projectArray[0].setAverageSolarLoads(0, 0, 0, 0);

					projectArray[0].setuValueRoof(0);
					projectArray[0].setuValueGroundFloor(0);
					projectArray[0].setuValueGlazing(0);
					projectArray[0].setuValueWalls(0);

					event.getButton().setCaption("Set Test Values");
					event.getButton().removeStyleName(Runo.BUTTON_DEFAULT);

				}
				projectArray[0].setUnlockedFacades();
			}
		});

		buttonContainer.addComponent(testValues);

		Button solarGlazingValues = new Button("Set Solar & Glazing");

		solarGlazingValues.addListener(new ClickListener() {

			boolean boolSolarGlazingClicked = false;

			public void buttonClick(ClickEvent event) {

				boolSolarGlazingClicked = !boolSolarGlazingClicked;

				if (boolSolarGlazingClicked) {
					projectArray[0].setFacadeOnePercentageFrame(20);
					projectArray[0].setFacadeOneSolarTransmittance(0.7d);
					projectArray[0].setFacadeOneShadingFactor(1.0d);
					projectArray[0].setFacadeTwoPercentageFrame(20);
					projectArray[0].setFacadeTwoSolarTransmittance(0.7d);
					projectArray[0].setFacadeTwoShadingFactor(1.0d);
					projectArray[0].setFacadeThreePercentageFrame(20);
					projectArray[0].setFacadeThreeSolarTransmittance(0.7d);
					projectArray[0].setFacadeThreeShadingFactor(1.0d);
					projectArray[0].setFacadeFourPercentageFrame(20);
					projectArray[0].setFacadeFourSolarTransmittance(0.7d);
					projectArray[0].setFacadeFourShadingFactor(1.0d);
					projectArray[0].setUnlockedFacades();

//					projectArray[0].setGroundFloorHeadHeight(2.25d);
//					projectArray[0].setGroundFloorCillHeight(0.5d);
//					projectArray[0].setGroundFloorReveal(0.1d);
//					projectArray[0].setFirstFloorHeadHeight(2.25d);
//					projectArray[0].setFirstFloorCillHeight(0.5d);
//					projectArray[0].setFirstFloorReveal(0.1d);
//					projectArray[0].setSecondFloorHeadHeight(2.25d);
//					projectArray[0].setSecondFloorCillHeight(0.5d);
//					projectArray[0].setSecondFloorReveal(0.1d);

					projectArray[0].setFacadeOneSurroundingFeaturesAverageHeight(6);
					projectArray[0].setFacadeOneSurroundingFeaturesAverageDistance(6);
					projectArray[0].setFacadeTwoSurroundingFeaturesAverageHeight(5);
					projectArray[0].setFacadeTwoSurroundingFeaturesAverageDistance(5);
					projectArray[0].setFacadeThreeSurroundingFeaturesAverageHeight(4);
					projectArray[0].setFacadeThreeSurroundingFeaturesAverageDistance(4);
					projectArray[0].setFacadeFourSurroundingFeaturesAverageHeight(3);
					projectArray[0].setFacadeFourSurroundingFeaturesAverageDistance(3);

					projectArray[0].setDiffuseTransmittanceText(DT_DG);
					projectArray[0].setLocationSetting(LS_SUB);
					projectArray[0].setAverageReflectanceOfInteriorSurfacesText(REF_LW);

					event.getButton().setCaption("Clear Solar & Glazing");
					event.getButton().addStyleName(Runo.BUTTON_DEFAULT);

				} else {

					projectArray[0].setFacadeOnePercentageFrame(0);
					projectArray[0].setFacadeOneSolarTransmittance(0);
					projectArray[0].setFacadeOneShadingFactor(0);
					projectArray[0].setFacadeTwoPercentageFrame(0);
					projectArray[0].setFacadeTwoSolarTransmittance(0);
					projectArray[0].setFacadeTwoShadingFactor(0);
					projectArray[0].setFacadeThreePercentageFrame(0);
					projectArray[0].setFacadeThreeSolarTransmittance(0);
					projectArray[0].setFacadeThreeShadingFactor(0);
					projectArray[0].setFacadeFourPercentageFrame(0);
					projectArray[0].setFacadeFourSolarTransmittance(0);
					projectArray[0].setFacadeFourShadingFactor(0);

//					projectArray[0].setGroundFloorHeadHeight(0);
//					projectArray[0].setGroundFloorCillHeight(0);
//					projectArray[0].setGroundFloorReveal(0);
//					projectArray[0].setFirstFloorHeadHeight(0);
//					projectArray[0].setFirstFloorCillHeight(0);
//					projectArray[0].setFirstFloorReveal(0);
//					projectArray[0].setSecondFloorHeadHeight(0);
//					projectArray[0].setSecondFloorCillHeight(0);
//					projectArray[0].setSecondFloorReveal(0);

					projectArray[0].setFacadeOneSurroundingFeaturesAverageHeight(0);
					projectArray[0].setFacadeOneSurroundingFeaturesAverageDistance(0);
					projectArray[0].setFacadeTwoSurroundingFeaturesAverageHeight(0);
					projectArray[0].setFacadeTwoSurroundingFeaturesAverageDistance(0);
					projectArray[0].setFacadeThreeSurroundingFeaturesAverageHeight(0);
					projectArray[0].setFacadeThreeSurroundingFeaturesAverageDistance(0);
					projectArray[0].setFacadeFourSurroundingFeaturesAverageHeight(0);
					projectArray[0].setFacadeFourSurroundingFeaturesAverageDistance(0);

					projectArray[0].setDiffuseTransmittanceText(null);
					projectArray[0].setLocationSetting(null);
					projectArray[0].setAverageReflectanceOfInteriorSurfacesText(null);

					event.getButton().setCaption("Set Solar & Glazing");
					event.getButton().removeStyleName(Runo.BUTTON_DEFAULT);
				}
			}
		});

		buttonContainer.addComponent(solarGlazingValues);

		Button distributeGlazingFromSolar = new Button("Auto Distribute Glazing");

		distributeGlazingFromSolar.addListener(new ClickListener() {

			public void buttonClick(ClickEvent event) {

				projectArray[0].setGlazingDistributionFromSolarLoads();
			}
		});

		buttonContainer.addComponent(distributeGlazingFromSolar);
		
		rooter.addComponent(buttonContainer, "top: 10px; right: 18px; z-index:1;");
		
		CssLayout margin = new CssLayout();
		margin.setMargin(true);
		margin.setWidth("100%");
		main.setContent(margin);

		Label title = new Label("Test H1");
		title.addStyleName(Runo.LABEL_H1);
		margin.addComponent(title);

		HorizontalLayout texts = new HorizontalLayout();
		//texts.setSpacing(true);
		texts.setWidth("100%");
		margin.addComponent(texts);

		Label text = new Label(
				"<h3>Test H3</h3><p>Curabitur commodo, est sed fringilla sagittis, nulla ipsum facilisis tellus, eu lobortis turpis velit sit amet elit.</p><p>Proin ut nibh turpis. Morbi eget orci risus. Sed sagittis, purus ut dapibus accumsan, ante felis molestie erat, quis luctus lacus nisi quis felis.</p>",
				Label.CONTENT_XHTML);
		texts.addComponent(text);
		texts.setExpandRatio(text, 1);		
		
		root.addComponent(new Label("<hr />", Label.CONTENT_XHTML));

		texts = new HorizontalLayout();
		texts.addStyleName(Runo.LAYOUT_DARKER);
		texts.setSpacing(true);
		texts.setMargin(true);
		texts.setWidth("100%");
		root.addComponent(texts);

		Button next = new Button("Test Button 2", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				right.setSelectedTab(samples);
			}
		});
		
		next.setWidth("100%");
		next.addStyleName(Runo.BUTTON_DEFAULT);
		next.addStyleName(Runo.BUTTON_BIG);
		texts.addComponent(next);
		texts.setComponentAlignment(next, Alignment.BOTTOM_LEFT);
		texts.setExpandRatio(next, 1);

		// Spacer
		text = new Label("");
		text.setWidth("20px");
		texts.addComponent(text);

		next = new Button("Test Button 3", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				right.setSelectedTab(styles);
			}
		});
		next.setWidth("100%");
		next.addStyleName(Runo.BUTTON_DEFAULT);
		next.addStyleName(Runo.BUTTON_BIG);
		texts.addComponent(next);
		texts.setComponentAlignment(next, Alignment.BOTTOM_LEFT);
		texts.setExpandRatio(next, 1);

		return rooter;
	}
	*/
	
	@Override
	public void transactionStart(Application application, Object transactionData) {
		if (transactionData instanceof HttpServletRequest) {
            HttpServletRequest request = (HttpServletRequest) transactionData;
            // When repainting the screen (f5)
            if (request.getParameter("repaintAll") != null) {
            	//System.out.println("Transaction Start");
            	login.executeJavaScript("$(function(){ $(\"label\").inFieldLabels(); });");
            }
            
			this.remoteAddress = resolveRemoteHost((HttpServletRequest) transactionData);
        }
	}

	@Override
	public void transactionEnd(Application application, Object transactionData) {
		//System.out.println("Transaction End");
		
	}

	private String resolveRemoteHost(HttpServletRequest request) {
		String remoteHost = request.getRemoteHost();
		
		if (remoteHost == null) {
			remoteHost = request.getRemoteAddr();
			if (remoteHost == null) {
				return "unknown";
			}
		}
		return remoteHost;
	}
	
	/*
	private Resource createPdf() {
        // Here we create a new StreamResource which downloads our StreamSource,
        // which is our pdf.
        StreamResource resource = new StreamResource(new Pdf(), "test.pdf?" + System.currentTimeMillis(), this);
        // Set the right mime type
        resource.setMIMEType("application/pdf");
        return resource;
    }
	*/
	
    private void displayPopup(int arrayIndex) {
        Window window = new Window();
        window.setStyleName(Runo.WINDOW_DIALOG);
        window.setModal(true);
        ((VerticalLayout) window.getContent()).setSizeFull();
        window.setResizable(true);
        window.setCaption("PDF Report (" + projectArray[arrayIndex].getProjName() + ")");
        window.setWidth("" + ((mainWindow.getBrowserWindowHeight() - 40) * 0.72));
        window.setHeight("" + (mainWindow.getBrowserWindowHeight() - 40));
        window.center();
        Embedded e = new Embedded();
        e.setSizeFull();
        e.setType(Embedded.TYPE_BROWSER);
        
        // Here we create a new StreamResource which downloads our StreamSource,
        // which is our pdf.
        StreamResource resource = new StreamResource(new PdfHelper(projectArray[arrayIndex], this), "report_" + System.currentTimeMillis() + ".pdf", this);
        // Set the right mime type
        resource.setMIMEType("application/pdf");

        e.setSource(resource);
        window.addComponent(e);
        getMainWindow().addWindow(window);
        
    }

    private void displayFeedback() {
        final Window window = new Window();
        //window.setStyleName(Runo.);
        window.setModal(true);
        ((VerticalLayout) window.getContent()).setSizeFull();
        window.setResizable(true);
        window.setCaption("User Feedback Form");
        window.setWidth("" + (mainWindow.getBrowserWindowWidth() / 2));
        window.setHeight("" + (mainWindow.getBrowserWindowHeight() / 2));
        window.center();
        
        VerticalLayout feedback_layout = new VerticalLayout();
        feedback_layout.setSizeFull();
        window.addComponent(feedback_layout);
        
        final TextArea textearea = new TextArea();
        textearea.setSizeFull();
		textearea.setNullSettingAllowed(true);
		textearea.setNullRepresentation("");

		feedback_layout.addComponent(textearea);
		feedback_layout.setExpandRatio(textearea, 9);
		
		Button buttonSubmitFeedback = new Button("Submit Feedback", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				String from = "feedback-noreply@fenestrapro.com";
		        String to1 = "dpalmer@fenestrapro.com";
		        String to2 = "swhelan@fenestrapro.com";
		        String to3 = "niall@fenestrapro.com";
		        String subject = "[Feedback] - (" + currentUserFirstName + " | " + currentCompanyName + ")";
		        
		        String message = "User:\t\t" + currentUserFirstName + "\n" +
		        				 "Company:\t" + currentCompanyName + "\n" +
		        				 "Main Tab:\t" + selectedTabName + "\n";
		        if (!selectedTabName.equalsIgnoreCase("home")) {
		        	message = message + "Left Tab:\t" + tabSheetLeft.getSelectedTab().getCaption() + "\n" +
	        				 			"Right Tab:\t" + tabSheetRight.getSelectedTab().getCaption() + "\n\n" + 
	        				 			textearea.getValue();
		        }
		        
		        SendMail sendMail = new SendMail(from, to1, to2, to3, subject, message);
		        sendMail.send();
		        
				getMainWindow().removeWindow(window);
				getMainWindow().showNotification("Feedback Submitted");
				//screenshot.makeScreenshot(mainWindow);
			}
		});

		Label vspacer = new Label("");
		vspacer.setHeight("15px");
		feedback_layout.addComponent(vspacer);
		
		buttonSubmitFeedback.setWidth("100%");
		buttonSubmitFeedback.addStyleName(Runo.BUTTON_DEFAULT);
		buttonSubmitFeedback.addStyleName(Runo.BUTTON_BIG);
		
		feedback_layout.addComponent(buttonSubmitFeedback);
		feedback_layout.setExpandRatio(buttonSubmitFeedback, 0);
		
        getMainWindow().addWindow(window);
    }
    
	@Override
	public void screenshotReceived(byte[] imageData) {
		StreamResource imageresource = new StreamResource(new MyImageSource(imageData), "screenshot.png", this);
		image.setSource(imageresource);
	}

	public class MyImageSource implements StreamResource.StreamSource {
	    private byte[] data;

	    public MyImageSource(byte[] rawData) {
	      data = rawData;
	    }

	    public InputStream getStream() {
	      return new ByteArrayInputStream(data);
	    }
	  }
}
